【问题标题】:Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in in my php file [duplicate]警告:mysql_num_rows() 期望参数 1 是资源,在我的 php 文件中给出的布尔值 [重复]
【发布时间】:2014-02-03 02:02:27
【问题描述】:

我有一个来自此代码的错误 错误是

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/quick/public_html/tvhd.in/xamii/Channel-Detail.php on line 62


Warning: Cannot modify header information - headers already sent by (output started at /home/quick/public_html/tvhd.in/xamii/Channel-Detail.php:62) in /home/quick/public_html/tvhd.in/xamii/Channel-Detail.php on line 64

一个人能帮上忙就好了

【问题讨论】:

  • 请参阅this answer 了解如何解决此问题。
  • 每天至少被询问 5 次。这些人在读什么书/教程???
  • 好吧,别再给它传递一个布尔值了。有什么问题? (哦,你的意思是可能有一个查询或其他信息可以说明这一点?你说的地狱

标签: php mysql sql


【解决方案1】:

错误检查。错误检查。错误检查!!!

// $result will be boolean FALSE if there is a failure in the query
// This is not the same as if there were 0 results
$result = mysql_query('SELECT * FROM SOMETABLE');

if (!$result) {
    // The query has an error, so you can't use mysql_num_rows
    die(mysql_error()); // <!-- This will tell you why. psuedo error checking!
}

// If we make it this far, its safe to use mysql_num_rows and $result
$rows = mysql_num_rows($result);

现在,停止使用 mysql_ 函数!它们已被弃用。看一眼在线文档 5 秒就会回答这个问题,并告诉你不要使用 mysql_。看大红框。

http://us1.php.net/manual/en/function.mysql-query.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-20
    • 2016-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多