如果数据库不存在,我正在尝试创建它。代码在这里:
<?php
// Connect to MySQL
$link = mysql_connect('host', 'user', 'pw');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
// Make studentdb the current database
$db_selected = mysql_select_db('StudentDB', $link);
if (!$db_selected) {
// If we couldn't, then it either doesn't exist, or we can't see it.
$sql = 'CREATE DATABASE StudentDB';
if (mysql_query($sql, $link)) {
echo "Database StudentDB created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
}
mysql_close($link);
?>
我收到此错误:
创建数据库时出错:用户“myusernamehere”拒绝访问数据库“StudentDB”
用户具有 dba 权限...我猜这是我的用户的权限错误...如何通过脚本授予用户权限并使该脚本工作?