query返回true而不是

query返回true而不是

This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result
                                
                                    (32个答案)
                                
                        
                                5年前关闭。
            
                    
我面临着非常奇怪的问题。
mysql_query返回true而不是SELECT的资源ID。

$query =  "SELECT s.id, s.lesson_code, l.lesson_name, t.teacher_name
           FROM student_comment s
           LEFT JOIN classes l
             ON s.lesson_code = l.lesson_code
           LEFT JOIN teacher t
             ON s.teacher_id = t.id
           WHERE s.school_id = '" .$_GET['school_id']. "'
           ORDER BY s.id DESC";


然而;当我在phpMyAdmin中执行此查询时,它会给我确切的结果。
但是相同的查询给我在PHP页面中出现以下错误。

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\web\htdocs\test\home\question.php on line 33
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\web\htdocs\test\home\question.php on line 35

最佳答案

$query =  "SELECT s.id, s.lesson_code, l.lesson_name, t.teacher_name
           FROM student_comment s
           LEFT JOIN classes l
           ON s.lesson_code = l.lesson_code
           LEFT JOIN teacher t
           ON s.teacher_id = t.id
           WHERE s.school_id = '" .$_GET['school_id']. "'
           ORDER BY s.id DESC";

$exe = mysql_query($query) or die(mysql_error());

while($fetch = mysql_fetch_array($exe))
{
    echo '<pre>'; print_r($fetch);
}

10-07 20:35