0

好的,所以我知道关于“为什么我会收到 mysql_fetch_array... 的警告”的问题已经被问了好几次了,我的问题是所有接受的答案都表明服务器吐出这个警告的原因是因为查询本身是不正确的...这不是我的情况。

下面是代码:

$dbhost = "host";
$dbuser = "user";
$dbpass = "pass";
$dbname= "db";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname) or die ('<META HTTP-EQUIV="Refresh" CONTENT="0;URL=Failed.php?dberror=1">');    

$token = mysql_escape_string($_GET['token']); 

$query = "SELECT * FROM newuser WHERE token='$token'";
$result = mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result)) {
   do stuff...
}

'while' 语句中的所有内容都执行得很好——它对数据库进行了一些更改,我可以验证这些更改正在发生。更重要的是,查询永远不会吐出任何错误细节。我已经尝试测试 $result===false 并询问错误信息但它也不会返回任何内容的情况。据我所知,查询字符串很好,没有失败。

我在这里做错了什么?除了 SQL 语句之外,PHP 不喜欢我的 While 参数是否有任何其他原因是不好的(我再次确信它还不错)?

另外,我知道我应该使用 mysqli/PDO ....我计划在不久的将来切换到它,但我只是想把头发拉出来,我不知道为什么它会失败吨。在这一点上,这更像是个人的事情......

感谢您的帮助,如果您需要任何其他信息,请告诉我。(PHP 5.3 版)

这是查询字符串 ($query) 的回显:

  SELECT * FROM newuser WHERE token='6e194f2db1223015f404e92d35265a1b'

这是查询结果的 var_dump ($result): resource(3) of type (mysql result)

4

4 回答 4

5
$query = "SELECT * FROM newuser WHERE token='$token'";
$result = mysql_query($query) or die(mysql_error());

while($row=mysql_fetch_array($result)) {
   do stuff...
}

If the die statement is not executed, $result is OK when you enter the while loop. The problem then is probably that you use $result for a query inside the loop as well, eventually leading to it being set to false.

于 2013-03-30T22:54:35.640 回答
2

So for now i can say that the problem is not the mysql_escape_string nether the using of mysql at all neither access privilege from user name and password and what i want to tell you is to test the $result and if it is a resource proceed with your while block like this

if(is_resource($result))
    {
        while($row = mysql_fetch_array($result))
            {//process your code here}
    }

and tell me if the code has been also executed :)

于 2013-03-30T22:35:41.857 回答
1

根据 查询正确mysql_。您收到的错误告诉您这$result是布尔值(假)。

$token来自哪里?您最好停止使用mysql_函数并使用准备好的语句和绑定参数。

于 2013-03-30T21:59:41.217 回答
0

你的逃跑是错误的试试这个

     $token = mysql_real_escape_string($_GET['token']);

代替$token = mysql_escape_string($_GET['token']);

此扩展自 PHP 5.5.0 起已弃用,并将在未来删除。

http://php.net/manual/en/function.mysql-real-escape-string.php

于 2013-03-30T22:06:50.360 回答