The CREATE DATABASE statement is used to create a MySQL database. We must add the CREATE DATABASE statement to the mysql_query() function to execute the command.
Ex: (Create database)
<?php
$host = "localhost";
$user = "";
$pass = "";
$conn = mysql_connect($host, $user, $pass);
if(!$conn )
{
die("Could not connect:" . mysql_connect_error());
}
echo "Connected successfully<br/>";
$sqlQuery = "CREATE Database mydatabase";
if(mysql_query( $conn,$sqlQuery)){
echo "Database mydb created successfully.";
}else{
echo "Sorry, database creation failed ".mysql_error($conn);
}
mysql_close($conn);
?>
Connected successfully
Database mydatabase created successfully.
In the above example first we create the connection with the database then we write statement to create a database of name mydatabase after that this statement is passed to mysql_query() along with the connection variable of the database.
© 2024 Easy To Learning. All Rights Reserved | Design by Easy To Learning