gpt4 book ai didi

MYSQL : problem with mysql_query

转载 作者:行者123 更新时间:2023-11-29 06:18:45 27 4
gpt4 key购买 nike

我需要你的帮助。这是什么意思?

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 4Warning: 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 password: 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'];

这是我第一次遇到这样的问题。有人可以向我解释一下如何解决这个问题吗?

最佳答案

该错误表示您没有连接到mysql。在运行查询之前,您需要连接到 mysql:

查看:

Connect to MySQL Database

你的代码应该是这样的:

$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'];

关于MYSQL : problem with mysql_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4961241/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com