Script breaking below MySQL queries, but no error being given?

前端 未结 1 1766

I really don\'t understand what the issue is here, I\'ve tried everything I can do diagnose the problem, and managed to isolate where I think the issue is being caused (see

1条回答
  •  太阳男子
    2020-12-22 10:48

    I think the problem is in this line:

    $size = mysql_num_rows($result) or die(mysql_error());
    

    when the num_rows call returns 0, the interpreter will parse the die(mysql_error()) part even if there is no error at all.

    Lesson: It's best to avoid ... or die() constructs. Do a proper check instead:

    $size = mysql_num_rows($result);
    
    if ($size === false) die(mysql_error()); // or, even better, trigger_error()
                                             // so mySQL errors aren't shown
                                             // in production
    

    0 讨论(0)
提交回复
热议问题