Jump to content
Larry Ullman's Book Forums

Call To A Member Function Setfetchmode() On Boolean

Recommended Posts

Hi Larry,
First I would like to express my satisfaction with your books,
PHP book 4, and the advanced one covering OOP.
I need your help here to figure out the way to solve this problem:

The book: "Object Oriented PHP"
(Fatal error: Call to a member function setFetchMode() on boolean)
In fact the script stop working at the end of start of the form up to the
and never run the query and the rest of the form.
- the submit input is not shown in the browser.
- I got the error notification by checking the view page source.
That is all for now.
Again, your books on PHP are great and the best among the ones I have ever read.

Link to comment
Share on other sites

This error occurs when you try to call a method on something that is not an object. In this case, the variable that should hold an object is actually a boolean. Make sure you actually create an object.


An example can be the MySQLi functions.If you look at MySQLi::query(), the function returns either false (on error) or an object of the type mysql_result. A bad SQL query will make the query fail and the function to return false. The next call to $result->fetch_all(); would therefor return the error above.


In you case, the error occurs when you try to call setFetchMode. It probably means your PDO query failed. Try something like this to reveal the error:

$query = "..."; // Your current query
$sth = $dbh->prepare($query);

// Get error array
$errors = $sth->errorInfo();
Link to comment
Share on other sites

Thank you both Antonio and Larray.

In fact there wasn't a mistake in Larry's original code, I was wondering! how come!

I solved it by changing the computer and the topic for a while and returned to it again from the start. I learned much out of it.


Link to comment
Share on other sites


  • Create New...