![]() |
|
Creating MySQL databases. Free online PHP and MySQL Web Database Programming Tutorial... |
| Lessons | Creating MySQL Database |
|
|
How to Create a MySQL Database? We us the CREATE DATABASE statement to create a database in MySQL. Its syntax follows: CREATE DATABASE database_name How to Create a MySQL Database in PHP? PHP provides the mysql_query() function to execute the SQL statements like above. This function is used to send a query or command to a MySQL connection. Let's see an example: <?php $con = mysql_connect("localhost", "adam" ,"ada"); if (!$con) { die('Error connecting database'); } if (mysql_query("CREATE DATABASE my_db", $con)) { echo "Database successfully created"; } else { echo "Error creating database!"; } mysql_close($con); ?> The above example creates a database called "my_db". |