dongzhu7329 2013-05-13 08:20
浏览 36
已采纳

mysql_num_rows()期望参数1是资源,第31行/home/domain/public_html/config.php中给出的布尔值[关闭]

I know that this is very frequently problem. I have two hosting A and B and one mysql base. On hosting A site works but the same web page (I copy file from A to B) on hosting B doesn't work perfectly. Host, login and password to date base is ok because i see news etc. But when i try login to my admin panel i see:

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/dmcmetal/domains/mydomain.com/public_html/config.php on line 31

I add to my config.php file mysql_error(); and now i see:

 Something is wrong in your syntax obok '=='1' LIMIT 1' w linii 1

Here is the part of config.php file:

function get_user_data($id=-1) {
if($id==-1) {
    $id=$_SESSION['id'];
}
$result=  mysql_query("SELECT * FROM `users` WHERE `id`=='{$id}' LIMIT 1");
if($result==FALSE)
    die(mysql_error());
if(mysql_num_rows($result)==0) { // 31 line
    return false;
}
return mysql_fetch_assoc($result);

}

Can anyone have idea why it works on hosting A and doesn't work on hosting B ?

  • 写回答

3条回答 默认 最新

  • duankang8114 2013-05-13 08:23
    关注

    There is a syntax error in your query, you are using double equals when mysql syntax requires a single one. This is causing the error since there is no number of rows. So please change to

    $result=  mysql_query("SELECT * FROM `users` WHERE `id` = '{$id}' LIMIT 1");
    

    Then I would like you to remember that mysql_* functions are deprecated so i would advise you to switch to mysqli or PDO

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

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)