Uncaught Error: Call to a member function execute()

A

Anonymous

Guest
I am in trouble with one part of my code. It seems to be working pretty fine on the localhost server, but when I upload the project to the webserver it has one error that I can't fix.

It says:

Fatal error: Uncaught Error: Call to a member function execute() on boolean in /home2/myserver/public_html/site/class/Articles.php:27 Stack trace: #0 /home2/myserver/public_html/site/noticias.php(14): Articles->getArticles() #1 /home2/myserver/public_html/site/index.php(3): include('/home2/baconboa...') #2 {main} thrown in /home2/myserver/public_html/site/class/Articles.php on line 27

Here's my code for getArticles() function and the error on line 27:
Code:
public function getArticles(){

		$query = '';
		if($this->id) {		
			$query = " AND p.id ='".$this->id."'";
		}
		$sqlQuery = "
			SELECT p.id, p.title, p.descricao, p.message, p.category_id, p.userid, p.imagem, u.first_name, u.last_name, p.status, p.created, p.updated, c.name as category
			FROM ".$this->postTable." p
			LEFT JOIN ".$this->categoryTable." c ON c.id = p.category_id
			LEFT JOIN ".$this->userTable." u ON u.id = p.userid
			WHERE p.status ='published' $query ORDER BY p.id DESC";
			
		$stmt = $this->conn->prepare($sqlQuery);		
		$stmt->execute();
		$result = $stmt->get_result();	
		return $result;
	}

my index has:
Code:
<?php 
    include('topo.php');
    include('noticias.php'); ?>
</div>
</body>
</html>

and noticias.php part is:
Code:
<?php 
include_once 'config/Database.php';
include_once 'class/Articles.php';
include_once 'painel/class/User.php';

$database = new Database();
$db = $database->getConnection();

$article = new Articles($db);
$article->id = 0;
$result = $article->getArticles();
$user = new User($db);
?>

I have tried a lot of things to solve the problem, but I DON'T REALLY KNOW HOW TO DO IT. It's my first time working with a server besides the local server so please, I beg you, help meeeeeeeeeeeeee
 
This error means you are trying to call a method on something that isn't a class; it's a boolean. If you look at the documentation for the prepare() function, you'll see that it can return a boolean "false" in the event of an error. This is what's happened. Take a look at your connection class to find out how to see what the error is.
 
Back
Top