致命错误:未捕获的异常'PDOException',消息为'SQLSTATE [42000]:4

I've been working on a school project which I didn't have a problem to, suddenly this error appears. I didn't edit something on the code. When I run it again this error appears.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7' And here is the other error I've been getting.

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7

This is the query that I made. I really could not find what the problem is.

    class Subject {        

    function getSubjectList($id) {
        global $db;            

        $sql = "SELECT class_id, c.subject_id, subject_desc, units, day, time
                FROM class c 
                JOIN subject s 
                ON  c.subject_id = s.subject_id
                JOIN lecturer l 
                ON c.lec_id = l.lec_id 
                WHERE l.lec_id = $id";

        $stmt = $db->query($sql);

        while($r = $stmt->fetch()) {
            $result[] = $r['class_id'];
            $result[] = $r['subject_id'];
            $result[] = $r['subject_desc'];
            $result[] = $r['units']; 
            $result[] = $r['day'];
            $result[] = $r["time"];
            $result[] = $r['class_id'];
        }

        return $result;            
    }
}

On this query, you have to specify the join type: http://dev.mysql.com/doc/refman/5.0/en/join.html

Look the example below:

SELECT class_id, c.subject_id, subject_desc, units, day, time
                FROM class c 
                INNER JOIN subject s 
                ON  c.subject_id = s.subject_id
                INNER JOIN lecturer l 
                ON c.lec_id = l.lec_id 
                WHERE l.lec_id = $id;