php 在非对象上调用成员函数 execute()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8999691/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
call to a member function execute() on a non-object
提问by Malloc
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
在服务器(不是本地主机)上运行的 php 版本是 5.2.17
回答by Pierre de LESPINAY
$stmt
is supposed to be an object with the method execute()
.
Seems like $this->db->prepare()
is not returning the good result.
$stmt
应该是具有方法的对象execute()
。
似乎$this->db->prepare()
没有返回好结果。
If $this->db
is a mysqli()
object you should bind the parameterslike that:
如果$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();
// ...
}
回答by xdazz
Check the sql you executed,
检查你执行的sql,
$this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements where type IN ('.$in_list.')');
does not return a valid statement object.
不返回有效的语句对象。
回答by suraj kumar
Swap the statement bind and execute and replace result with param, It will work fine
交换语句绑定并执行并用参数替换结果,它会正常工作
$stmt = $this->db->prepare('SELECT libelle,activite,adresse,tel,lat,lng FROM etablissements
where type IN ('.$in_list.')');
$stmt->bind_param($libelle,$activite,$adresse,$tel,$lat,$lng);
$stmt->execute();
回答by nz-io
Your db object is null. Check if you close the connection too early or somehow you override it to null.
您的 db 对象为空。检查您是否过早关闭连接或以某种方式将其覆盖为空。