Question: How can we create a database using php and mysql?
Answer: mysql_create_db()
Example:
$link = mysql_connect(’localhost’‚ ’mysql_user’‚ ’mysql_password’);
if (!$link)
{
die(’Could not connect: ’ . mysql_error());
}
$sql = ’CREATE DATABASE my_db’;
if (mysql_query($sql‚ $link))
{
echo "Database my_db created successfully\n";
}
else
{
echo ’Error creating database: ’ . mysql_error() . "\n";
}
?>
No comments:
Post a Comment