Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
sakin

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.
thanks

Share this post


Link to post
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);
$sth->execute();

// Get error array
$errors = $sth->errorInfo();
print_r($errors);

Share this post


Link to post
Share on other sites

Thanks much for the nice words. I really appreciate it. Antonio's input is spot on. If you have any further problems with this, it'd really help to know the exact code or script you're using.

Share this post


Link to post
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.

thanks

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...