PHP MySQL Create Database
From w3cyberlearnings
Contents |
PHP MySQL Create Database
Create a new database.
Syntax
$sql = "CREATE DATABASE IF NOT EXISTS database_name"; mysql_query($sql,$connection);
Example 1
<?php define('HOST', 'localhost'); define('USER', 'root'); define('PASS', 'yeething'); $connection = mysql_connect(HOST, USER, PASS); if (!$connection) { die("can not connect to the server!<br/>"); } else { echo 'connected and ready to use<br/>'; $sql = "CREATE DATABASE IF NOT EXISTS woowood"; if(mysql_query($sql,$connection)) { echo "Create woowood database successfully<br/>"; } else { echo "Error creating database: ". mysql_error(). "<br/>"; } } mysql_close($connection); ?>
Output
connected and ready to use Create woowood database successfully