MySQLi 可捕获的致命错误
我正在使用准备好的语句和 MySQLi,目前遇到此错误。
PHP Catchable fatal error: Object of class mysqli_stmt could not be converted to string in /Users/me/path/to/project/ModelBase/City.php on line 31
它来自的代码(完整功能):
function select($query, $limit)
{
$query = "%".$query."%";
$con = ModelBase::getConnection();
$sql = "SELECT name FROM cities WHERE name LIKE ? LIMIT ?";
$query = $con->prepare($sql) or die("Error preparing sql in City ".parent::$db_conn->error);
$query->bind_param("si", $query, $limit) or die("Error binding params in City ".parent::$db_conn->error);
$query->execute() or die("Error executing query in City");
$tmp = "";
$res = $query->bind_result($tmp);
while($query->fetch());
{
$citylist[] = $tmp;
}
$query->close();
}
像 31 一样是 $query->execute()。我找不到任何有关此问题的信息,这与我构建的其他系统几乎相同的语法,但从未遇到过此问题。
I'm using prepared statements and MySQLi, and am currently getting this error.
PHP Catchable fatal error: Object of class mysqli_stmt could not be converted to string in /Users/me/path/to/project/ModelBase/City.php on line 31
The code it's coming from (full function):
function select($query, $limit)
{
$query = "%".$query."%";
$con = ModelBase::getConnection();
$sql = "SELECT name FROM cities WHERE name LIKE ? LIMIT ?";
$query = $con->prepare($sql) or die("Error preparing sql in City ".parent::$db_conn->error);
$query->bind_param("si", $query, $limit) or die("Error binding params in City ".parent::$db_conn->error);
$query->execute() or die("Error executing query in City");
$tmp = "";
$res = $query->bind_result($tmp);
while($query->fetch());
{
$citylist[] = $tmp;
}
$query->close();
}
Like 31 is the $query->execute(). I can't find any information about this, and this is almost identical syntax to other systems I've built and never had this issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题在于您在两个上下文中使用
$query
。一次作为 SQL 字符串,一次准备语句:因此当您运行此行时:
实际查询的执行将崩溃。
I think the problem is that you are using
$query
in two contexts. Once as a SQL string, and once to prepare your statement:so when you run this line:
execution of the actual query will crash.