I can create database manually by going to cpanel. But I’d like to create databases using php. I’ve tried using the code from w#school.com , but it don’t work. How do i create database using php?
<?php
$con = mysql_connect("localhost",cpname_DbUsername,password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
if (mysql_query("CREATE DATABASE " . cpName_NewDbName,$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
mysql_close($con);
?>
The above code give me error 🙁
btw, i tried to ask in hostgator sup[port forum but i cant make a new threat in their forum 🙁
On a shared host, you won’t have permissions to create a database through PHP because they regulate the number of databases you can have. You’ll need to do it through their control panel. On a sidenote, you should probably use PDO (or a more powerful abstraction layer if the app warrants it) for a new webapp. php_mysql is deprecated. Also, w3schools is a bad, non-authoritative resource.