在非对象MySQLi上调用成员函数bind_param() [英] Call to a member function bind_param() on a non-object MySQLi

查看:38
本文介绍了在非对象MySQLi上调用成员函数bind_param()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我试图更新一个博客条目,并且在我尝试运行脚本时,我得到了对非对象上的成员函数bind_param()的调用.我已经进行了广泛的研究,以查看自己是否可以修复它,但是我一定会缺少一些东西.

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.

<?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();

?>

预先感谢

奥斯丁

更新:这是数据库连接

我为调试目的添加了额外的$ mysqli连接,即使没有它也会发生错误.

I added the extra $mysqli connection for debugging purposes, and the error occurs even without it.

推荐答案

$stmt可能是false.

if ($stmt = $mysqli->prepare(...)) {
    $stmt->bind_param(...);
    ...
}
else {
    printf("Errormessage: %s\n", $mysqli->error);
}

这篇关于在非对象MySQLi上调用成员函数bind_param()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆