I know there are few other questions on here with this title, but they seem to be case specific or I just can't wrap my head around it but I'm getting that error on this code, and I can't figure out why.
$db = new PDO($dsn, $username, $password);
$query = "Select * FROM book INNER JOIN course
ON book.course = course.courseID
ORDER BY courseTitle";
//query result
$books = array();
$sth = $db->query($query);
while( $row = $db->fetch(PDO::FETCH_ASSOC) ) {
$books[] = $row; // appends each row to the array
}
I thought maybe my query was wrong, so I tried an example from a PDO
tutorial, and I got the same type of error. Is there something I have to declare or am I leaving something out?
fetch
on$sth
, not on$db
.query
returnedfalse
because your query was bad. Usevar_dump($db->errorInfo())
to figure out what's wrong.