php mysql_num_rows() 期望参数 1 是资源,布尔值在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7766418/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql_num_rows() expects parameter 1 to be resource, boolean given in
提问by Simone Serafini
Possible Duplicate:
Warning: mysql_num_rows() expects parameter 1 to be resource,
I'm new in this forum. I'm building a search within my site. I have a problem with the DB. It's giving me this:
我是这个论坛的新手。我正在我的网站内建立一个搜索。我的数据库有问题。它给了我这个:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\Program Files (x86)\EasyPHP-5.3.5.0\www\searchscript\search.php on line 86
I'll show you the code section where it gives me such error
我会告诉你代码部分,它给了我这样的错误
line 82: $query = "SELECT * FROM dreams WHERE titolo,titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC ";
line 85: $numresults=mysql_query($query);
line 86: $numrows=mysql_num_rows($numresults); //error
Now I tried to see what is the problem behind the query and it's telling me this:
现在我试图看看查询背后的问题是什么,它告诉我:
SELECT * FROM dreams WHERE titolo, titch LIKE "%tags%" ORDER BY id_dreams DESC
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'titch LIKE "%tags%" ORDER BY id_dreams DESC' at line 1
您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的“titch LIKE "%tags%" ORDER BY id_dreams DESC' 附近使用的正确语法
The code behind this is:
这背后的代码是:
$query = "SELECT * FROM dreams WHERE titolo, titch LIKE \"%$trimmed%\" ORDER BY id_dreams DESC ";
$result = mysql_query($query) or die($query."<br/><br/>".mysql_error());
回答by piddl0r
The mysql_query is returning a boolean value meaning the sql query is probably failing and you're getting a false returned rather than a mysql resource.
mysql_query 正在返回一个布尔值,这意味着 sql 查询可能失败,并且您返回的是 false 而不是 mysql 资源。
Have you checked your query?
你检查过你的查询吗?
回答by Lightness Races in Orbit
You forgot to check whether $num_results
is a MySQL result resource. In this case your query errored, so it's FALSE
instead.
您忘记检查是否$num_results
是 MySQL 结果资源。在这种情况下,您的查询出错了,所以FALSE
改为。
Re-read the documentation for mysql_query
and ensure you program for allpossible cases.
重新阅读文档mysql_query
并确保您针对所有可能的情况进行编程。