CREATE DATABASE Function
2.We can create MySQL database with the use of mysql_create_db("Database Name").
mysql_create_db("Database Name") function is deprecated as of PHP 5.5.0, and will be removed in the future.
Syntax
CREATE DATABASE dbname;
Example: 1
<?php
$hostname = "localhost";
$username = "root";
$password = "";
$con = mysql_connect("$hostname", "$username", "$password");
if ($con)
echo "Connection is succeed<br>";
else
die("Could not connect: " . mysql_error());
$sql = "CREATE DATABASE Aspell";
$retval = mysql_query( $sql, $con);
if($retval )
echo "Database Aspell created successfully";
else
die("Could not create database: " . mysql_error());
mysql_close($con);
?>
$hostname = "localhost";
$username = "root";
$password = "";
$con = mysql_connect("$hostname", "$username", "$password");
if ($con)
echo "Connection is succeed<br>";
else
die("Could not connect: " . mysql_error());
$sql = "CREATE DATABASE Aspell";
$retval = mysql_query( $sql, $con);
if($retval )
echo "Database Aspell created successfully";
else
die("Could not create database: " . mysql_error());
mysql_close($con);
?>
Output
Connection is succeedDatabase Aspell created successfully
No comments:
Post a Comment