Create MySQL Database in PHP

How to create a MySQL Database in PHP?

Questions by abhishek ankur

Showing Answers 1 - 2 of 2 Answers


  • Mar 8th, 2010

 mysql_query("CREATE DATABASE databasename", connector) is the answer. Where mysql_query() is the PHP function that uses the CREATE DATABASE mysql command.

Here is a small code snippet. I have marked the PhP line to create a database in bold.


$db_connect = mysql_connect("hostname","user","password");
if (!$db_connect)

  die('Could not connect: ' . mysql_error());

if (mysql_query("CREATE DATABASE my_db",$db_connect))
  echo "Database created successfully";
  echo "Error creating database: " . mysql_error();


  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions