'警告:mysql_fetch_array()期望参数1为资源,布尔值在...中给出,但是我的查询是正确的 [英] 'Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in...' but my query is correct

查看:82
本文介绍了'警告:mysql_fetch_array()期望参数1为资源,布尔值在...中给出,但是我的查询是正确的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,所以我知道有关为什么我用mysql_fetch_array发出此警告..."的问题已问了好几次,我的问题是所有可接受的答案都指出服务器将此警告吐出来的原因是因为查询本身是不正确的...我不是这种情况.

Ok, so I know the question about 'why am I getting this warning with mysql_fetch_array...' has been asked several times, my problem is all the accepted answers state that the reasons the server is spitting this warning out is because the query itself is incorrect...this is not the case with me.

这是下面的代码:

$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的情况并询问错误信息,但随后它也不会返回任何内容.据我所知,查询字符串很好并且没有失败.

Everything within the 'while' statement is being executed just fine - it makes some changes to the DB which I can validate is happening. More importantly, the query never spits out any error details. I've tried testing for cases where $result===false and asking for error info but it won't return anything then either. From what I can tell, the query string is fine and is not failing.

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

What am I doing wrong here? Could there any other reason why PHP doesn't like my While parameters other than the SQL statement is bad (which again, I'm convinced it's not bad)?

另外,我知道我应该使用mysqli/PDO....我计划在不久的将来切换到该版本,但是我只是想尽一切努力而拔掉头发,我不知道为什么不会的.在这一点上,这更是个人的事...

Also, I know I should be using mysqli/PDO....I plan to switch over to that in the near future, but I'm pulling my hair out just trying to make this work and I have no idea why it won't. It's more of a personal thing at this point...

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

Thanks for your help, and let me know if you need any additional info. (PHP Version 5.3)

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

Here is an echo of the query string ($query):

  SELECT * FROM newuser WHERE token='6e194f2db1223015f404e92d35265a1b'

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

And here is a var_dump of the query results ($result): resource(3) of type (mysql result)

推荐答案

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

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

如果未执行die语句,则进入while循环时$result是确定的.然后的问题可能是您在循环内也使用$result进行查询,最终导致将其设置为false.

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.

这篇关于'警告:mysql_fetch_array()期望参数1为资源,布尔值在...中给出,但是我的查询是正确的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆