I'm trying to create a database if it does not exist. Code is here:
我正在尝试创建一个数据库,如果它不存在。代码在这里:
<?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);
?>
I'm getting this error:
我收到这个错误:
Error creating database: Access denied for user 'myusernamehere' to database 'StudentDB'
创建数据库时出错:用户'myusernamehere'拒绝访问数据库'StudentDB'
the user has dba permissions...I'm guessing this is a permission error for my user....how can I give the user permission through the script and make this script work?
用户拥有dba权限...我猜这是我的用户的权限错误....如何通过脚本授予用户权限并使此脚本有效?
2 个解决方案
#1
0
the users you are trying to use have no priviledges to use CREATE
您尝试使用的用户没有使用CREATE的权限
try to switch to another user that have all the priviledges needed on manipulting the database or add the needed priviledges to the user you are using
尝试切换到另一个用户,该用户拥有操纵数据库所需的所有权限,或者向您正在使用的用户添加所需的权限
#2
0
it happend to me and the following solved the problem:
它发生在我身上,以下解决了这个问题:
- first before using code to editing the database go to the main localhost/index.php page then choose phpMyAdmin database manager
- after than make sure that you are loged in as admin
首先在使用代码编辑数据库之前转到主localhost / index.php页面,然后选择phpMyAdmin数据库管理器
之后确保你作为管理员进入
#1
0
the users you are trying to use have no priviledges to use CREATE
您尝试使用的用户没有使用CREATE的权限
try to switch to another user that have all the priviledges needed on manipulting the database or add the needed priviledges to the user you are using
尝试切换到另一个用户,该用户拥有操纵数据库所需的所有权限,或者向您正在使用的用户添加所需的权限
#2
0
it happend to me and the following solved the problem:
它发生在我身上,以下解决了这个问题:
- first before using code to editing the database go to the main localhost/index.php page then choose phpMyAdmin database manager
- after than make sure that you are loged in as admin
首先在使用代码编辑数据库之前转到主localhost / index.php页面,然后选择phpMyAdmin数据库管理器
之后确保你作为管理员进入