Friday, November 15, 2019

mysqli - Fatal error: Call to a member function execute() on boolean in /home/*****/public_html/lnews.php on line 22





code:



$results = $mysqli->prepare("SELECT news_title FROM news ORDER BY posted_time DESC");
$results->execute();
$results->bind_result($news_title);


When I execute the code then it will return Fatal error: Call to a member function execute() on boolean in /home/*****/public_html/lnews.php on line 22. So, How can I fix this issue ?please help



Thank You



Answer



There is some error from database due to this the prepare method returns FALSE, on success this method returns prepared statement.



You can see the logs to determine the database error. Also, you should change your code in the following way and throw some exception in else.



$results = $mysqli->prepare("SELECT news_title FROM news ORDER BY posted_time DESC");
if($results !== false) {
$results->execute();
$results->bind_result($news_title);
}



In this case if false return (if there is database error) the execute method would not be invoked.


No comments:

Post a Comment

hard drive - Leaving bad sectors in unformatted partition?

Laptop was acting really weird, and copy and seek times were really slow, so I decided to scan the hard drive surface. I have a couple hundr...