开发者

MYSQL : problem with mysql_query

开发者 https://www.devze.com 2023-02-10 00:12 出处:网络
I need your help. What does this mean? Warning: mysql_query() [function.mysql-query]: Access denied for user

I need your help. What does this mean?

Warning: mysql_query() [function.mysql-query]: Access denied for user 
        'ODBC'@'localhost' (using password: NO) in 
        C:\xampp\htdocs\THESIS\std_results.php on line 4

Warning: mysql_query() [function.mysql-query]: A link to the server could 
        not be established in C:\xampp\htdocs\THESIS\std_results.php on line 4
        Access denied for user 'ODBC'@'localhost' (using p开发者_JS百科assword: NO)

This is the code that I used when I got that message.

$answer = mysql_query("SELECT * FROM tbl_answers") or die(mysql_error());
$r = mysql_fetch_assoc($answer);  
echo $r['id_exp'];

This is my first time encountering this kind of problem. Can someone explain to me how I can fix this?


The error means you are not connected to mysql. You need to connect to mysql before running your query:

Check out:

Connect to MySQL Database

Your code should be like this:

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'dbname';
mysql_select_db($dbname);

$answer = mysql_query("SELECT * FROM tbl_answers") or die(mysql_error());
$r = mysql_fetch_assoc($answer);
echo $r['id_exp'];


I think (using password: NO) specifically indicates that the incorrect password is being supplied. If you've got a database client or another script that successfully connects to your desired database, compare those credentials to the ones used by mysql_connect() in the offending script.

If not, you may have to go into your provider's cPanel or hosting management tool and see if you can find the correct credentials in there.

Good luck.

0

精彩评论

暂无评论...
验证码 换一张
取 消