本文介绍了警告:mysql_num_rows()期望参数1为给定的资源布尔值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我刚刚将站点更改为新服务器,现在此代码出现错误:

I've just changed a site over to a new server, and now I'm getting an error with this code:

<?php
    $result = mysql_query("SELECT * FROM trends ");
    $num_rows = mysql_num_rows($result);
    echo "<strong>" . $num_rows . "</strong>";
?>

错误是:

警告:mysql_num_rows()期望参数1为资源,给定布尔值.

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given.

我该如何解决?

干杯.

推荐答案

如果mysql_query失败,则返回false.

Your mysql_query return false if it fails.

因此,在使用结果之前,您需要检查查询是否失败(在这种情况下).

Therefore you need to check if the query failed (which is the case here) before using the result.

这篇关于警告:mysql_num_rows()期望参数1为给定的资源布尔值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:57