PHP-MySQL Lesson – Create Database

Creating a Database

The CREATE DATABASE statement in sql is used to create a database in MySQL. In PHP,mysql_query() function is used to execute sql query like insert, delete, update, select etc.

Here is an example PHP script that creates a database in MySQL: save it asphp_createDB.php

//including the database connection file
if (!mysql_query("CREATE DATABASE employee")) die(mysql_error());
 echo "success in database creation.";

In our example we have used include() function, this function takes all the content in a specified file and includes it in the current file. Then, the mysql_query() function executes the CREATE DATABASE statement, and a new database in MySQL. The die statement will execute if the connection fails and display the error message.

, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.