在这个create
函数中,我试图创建一个数据库。但是,它无法创建并显示错误Error creating database: Access denied.
因此,这意味着存在连接并且它通过了第一次检查。然后当mysql_query
被调用时,它不会返回true。任何人都可以帮忙吗?
function create($dbName, $tbName, $fields, $types_sizes, $PK)
{
$sql = null;
$con = mysql_connect("borg.cs.up.ac.za","username", "password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
if(mysql_query("CREATE DATABASE". $dbName, $con))
{
echo "Database created";
$dbExists = 1;
}
else
{
echo "Error creating database: " . mysql_error();
$dbExists = 0;
}
$i = 0;
if(($con)&&($bdExists = 1))
{
$sql . "CREATE TABLE " . $tbName . "(";
while($i < count($fields))
{
$sql . $fields[$i] . " " + $types_sizes[$i] . ",";
$i++;
}
if($PK != null)
{
$sql . "PRIMARY KEY (" . $PK .")";
}
}
mysql_query($sql,$con);
mysql_close($con);
}
}