php - mysql_num_rows() : supplied argument is not a valid MySQL result resource

标签 php sql mysql warnings mysql-num-rows

<分区>

if(mysql_num_rows($result))
{
echo "no match found!";
}

它抛出一个错误- 警告:mysql_num_rows():提供的参数不是第 72 行 D:\Hosting\6448289\html\includes\getQuestion.php 中的有效 MySQL 结果资源

最佳答案

你需要检查mysql_query的返回值

$query = 'YOUR QUERY';
$result = mysql_query($query);
if (!$result) {
    trigger_error('Invalid query: ' . mysql_error()." in ".$query);
}
// go ahead and fetch the results using mysql_num_rows.

如果 mysql_query 失败,它返回 boolean false 而不是 resource

当您将此 boolean 值传递给 mysql_num_rows 时,您会收到此错误。

关于php - mysql_num_rows() : supplied argument is not a valid MySQL result resource,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3698740/

相关文章:

javascript - 当我使用 ajax 从 "echo"PHP 获取 html 代码时,我需要继续执行 JS 代码

php - 为 Laravel 5.4 创建自己的邮件提供程序

PHP 函数只能工作一次

php - 如果在 mysql 表中找不到项目,如何重定向到另一个页面?

mysql - 如何在 Laravel Eloquent 中使用 MIN 和 MAX sql 查询

php - Laravel 改变外键约束

sql - SQL Server 中嵌套查询有结果或没有结果时如何返回 Yes 或 No?

SQL 按 LIKE 模式分组

sql - bigquery 从日期中减去 3 个工作日

php - MySQL:是否可以缩短错误消息?