PHP/MySQL:未找到匹配项时返回什么?
我想使用 PHP 来查找是否没有找到匹配项。我尝试了以下操作,但“is_resource()”始终返回 true。
$result = mysql_query('...');
if(is_resource($result)){
// Results are found
}
I want to use PHP to find out if no matches are found. I tried the following, but "is_resource()" always returns true.
$result = mysql_query('...');
if(is_resource($result)){
// Results are found
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
mysql_num_rows()
就可以了。http://php.net/manual/en/function.mysql-num -rows.php
mysql_num_rows()
will do the trick.http://php.net/manual/en/function.mysql-num-rows.php
因此,只要您能够正确访问数据库,$result 就始终是一种资源。并且 mysql_num_rows() 假定查询本身已成功运行。我想说尝试这样的事情:
希望有一点帮助=)
如果需要,请在此处查看更多信息:http://www.php。 net/manual/en/function.mysql-query.php
So $result will always be a resource as long as you have proper access to the database. And mysql_num_rows() assumes that the query itself ran successfully. I'd say try something like this:
Hope that helps a little =)
Look here for more information if you need: http://www.php.net/manual/en/function.mysql-query.php
这就是你想要的: mysql_num_rows()
This is what you want: mysql_num_rows()
如果查询失败,mysql_query 将返回 false,因此您可以像这样检查代码:
或者您可以像上面的人所述使用 mysql_num_rows 。
但你真的应该研究 MySQLi 它是一个内置的数据库类。学习它并使用它。你的生活将会变得更加轻松。
If the query fails it mysql_query will return false so you can check your code like this:
Or you could use mysql_num_rows like the people above have stated.
But you should really be looking into MySQLi it's a built in database class. Learn it and use it. Your life will be so much easier.