致命错误:在student_db中的非对象上调用成员函数fetch()

时间:2014-08-01 19:47:59

标签: php mysql

在student_db的第22行收到致命错误。

function get_student_by_id($studentID) {  //Fatal error on line 22 which is (get_student_by_id).
    global $db;
    $query = "SELECT * FROM student_table
          WHERE StudentID = $studentID";
    try {
        $student = $db->query($query);
        $student = $student->fetchall();
        return $student;
    } catch (PDOException $e) {
        $error_message = $e->getMessage();
        include('../errors/database_error.php');
        exit();
    }
}

错误消息

( ! ) Fatal error: Call to a member function fetch() on a non-object in 
C:\wamp\www\CRSProject\model\student_db.php on line 22
Call Stack
#   Time    Memory  Function    Location
1   0.0007  164648  {main}( )   ..\index.php:0
2   0.0139  225544  get_student_by_id( )    ..\index.php:51

0 个答案:

没有答案