To create a database connection and query using PHP programming language, use the below PHP code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php // Where $servername, $username, $password should be defined //beforehand by the developer. $connection = new mysqli($servername, $username, $password); //To check if the connection was successful: if ($conn->connect_error) { die("Connection error: " . $conn->connect_error); } //Create database query: $sql = "CREATE DATABASE PRODUCT"; if ($conn->query($sql) === TRUE) { echo "Database successfully created"; } else { echo "Error while creating database: " . $conn->error; } ?> |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.