php 在非对象 MySQLi 上调用成员函数 bind_param()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17768200/
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 bind_param() on a non-object MySQLi
提问by Austen
Okay, so I'm trying to update a blog entry, and I'm getting Call to a member function bind_param() on a non-object when I try to run the script. I have done extensive research to see if I could fix it myself, but I must be missing something.
好的,所以我正在尝试更新博客条目,当我尝试运行脚本时,我正在调用非对象上的成员函数 bind_param()。我已经做了广泛的研究,看看我是否可以自己修复它,但我一定是遗漏了一些东西。
<?php
$stmt = $mysqli->prepare("UPDATE blogentries SET
headline = ?,
image = ?,
caption = ?,
article = ?
WHERE id = ?");
$stmt->bind_param('ssssi',
$_POST['headline'],
$_POST['image'],
$_POST['caption'],
$_POST['article'],
$_POST['id']);
$stmt->execute();
$stmt->close();
?>
Thanks in advance,
提前致谢,
Austen
奥斯汀
Update: Here's the db connect
更新:这是数据库连接
I added the extra $mysqli connection for debugging purposes, and the error occurs even without it.
我添加了额外的 $mysqli 连接用于调试目的,即使没有它也会发生错误。
回答by bitWorking
$stmt
is probably false
.
$stmt
大概是false
。
if ($stmt = $mysqli->prepare(...)) {
$stmt->bind_param(...);
...
}
else {
printf("Errormessage: %s\n", $mysqli->error);
}
回答by Daniel W.
I solved that by testing the queries manually. It turned out to be a matter of putting each field name between back ticks and removing any quotes against the parameters labeled with question marks inside the query.
我通过手动测试查询解决了这个问题。结果证明是将每个字段名称放在反引号之间并删除针对查询中标有问号的参数的任何引号。
回答by FullStackEngineer
If all the connections to the database are correct, try looking for the syntax in the query. For me, I was performing a join and did not specify the "TABLENAME" in the where clause-field for which both the tables have a column.
如果与数据库的所有连接都正确,请尝试在查询中查找语法。对我来说,我正在执行连接并且没有在两个表都有一列的 where 子句字段中指定“TABLENAME”。