0

I have the following bit of code:

ob_start();
$host="localhost"; // Host name
$username="admin"; // Mysql username
$password=""; // Mysql password
$db_name="my_db_m"; // Database name
$tbl_name="members"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB :".mysql_error());

// Define $myusername and $mypassword 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword']; 

When I attempt to login, I get: cannot select DB :Access denied for user ''@'localhost' to database 'my_db_m'

I am using xampp. I used phpMyAdmin to create a database called 'my_db_m'. I created a table named 'members'.

Am I missing something? I am connecting to the mysql server yet unable to access the database...

4

2 回答 2

0

您可能需要授予admin用户访问权限。

GRANT ALL ON my_db_m.* TO 'admin'@'localhost';

这是非常全面的,因为它授予所有权利,您可能希望将一般用途的访问限制为类似

GRANT INSERT, UPDATE, SELECT, DELETE ON my_db_m.* TO 'admin'@'localhost';
于 2013-10-14T19:50:33.587 回答
0

简单的

GRANT USAGE ON my_db_m TO user@localhost IDENTIFIED BY 'passwd';

如果您想授予任何数据库使用权:

GRANT USAGE ON *.*
于 2013-10-14T19:56:50.400 回答