dtu15253 2012-04-15 21:41
浏览 29
已采纳

错误日志中的mysql_num_rows

I am encountering an error. My log is as follows:

PHP Warning:  mysql_num_rows(): supplied argument is not 
a valid MySQL result resource in     
/home/domain/public_html/index.php on line 96

My code is as followsL line 96:

mysql_num_rows(mysql_query("SELECT * FROM `table` WHERE 
UNIX_TIMESTAMP(`date`)>$user_last_visit"));

What could cause this error?

  • 写回答

4条回答 默认 最新

  • dongyue6199 2012-04-15 21:49
    关注

    You put two functions into each other directly:

    mysql_num_rows(mysql_query(...));
    

    Technically this is possible to do (function 1 returns something that becomes the parameter of function 2), however, in case function 1 returns something that function 2 can not deal with, you get errors.

    That happens in your case. Instead store the return value into a variable and do error handling your own:

    $result = mysql_query(...);
    if (!$result) {
        throw new Exception(sprintf('Database query failed: %s', mysql_error()));
    }
    $num_rows = mysql_num_rows($result);
    

    Proper error handling is crucial for solid programming, so take care about return values. When in doubt double-check for the function in question with the PHP manual which is really a great resource. See mysql_query.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 matlab实现基于主成分变换的图像融合。
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊