Call a member function execute () on a non-object

My script containing this error:

$stmt = $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN ('.$in_list.')'); $stmt->execute(); $stmt->bind_result($libelle,$activite,$adresse,$tel,$lat,$lng); 

The php version running on the server (not localhost) is 5.2.17

+4
source share
3 answers

$stmt must be an object with the execute() method.
It seems that $this->db->prepare() does not return a good result.

If $this->db is a mysqli() object, you must bind the parameters :

 if ($stmt = $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN (?)')) { $stmt->bind_param("s", $in_list); $stmt->execute(); // ... } 
+5
source

Check the executed sql,

 $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN ('.$in_list.')'); 

does not return a valid operator object.

+1
source

Your db object is NULL. Check if you close the connection too sooner or later, or somehow redefine it to zero.

-2
source

Source: https://habr.com/ru/post/1392869/


All Articles