在非对象上调用成员函数execute()(call to a member function execute() on a non-object)

包含该错误的脚本是这样的:

$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);

在服务器(而不是localhost)上运行的php版本是5.2.17

My script containing that error is this:

$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

最满意答案

$stmt应该是方法execute()的对象。 好像$this->db->prepare()没有返回好结果。

如果$this->db是一个mysqli()对象,你应该绑定这样的参数 :

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(); // ... }

$stmt is supposed to be an object with the method execute(). Seems like $this->db->prepare() is not returning the good result.

If $this->db is a mysqli() object you should bind the parameters like that:

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(); // ... }在非对象上调用成员函数execute()(call to a member function execute() on a non-object)

包含该错误的脚本是这样的:

$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);

在服务器(而不是localhost)上运行的php版本是5.2.17

My script containing that error is this:

$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

最满意答案

$stmt应该是方法execute()的对象。 好像$this->db->prepare()没有返回好结果。

如果$this->db是一个mysqli()对象,你应该绑定这样的参数 :

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(); // ... }

$stmt is supposed to be an object with the method execute(). Seems like $this->db->prepare() is not returning the good result.

If $this->db is a mysqli() object you should bind the parameters like that:

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(); // ... }