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

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

问题描述

我试图在此准备好的语句中绑定一个变量,但我不断收到错误:

I am trying to bind a variable in this prepared statement, but i keep receiving the error:

Call to a member function bind_param() on a non-object

该函数被调用,并且变量被传递给它.当我将函数更改为仅回显变量时,该变量会在页面上正常打印,但是如果我尝试在此处进行绑定,则会收到错误消息.有人可以帮忙吗?

The function is called, and variables are passed to it. When i change the function to just echo the variable, the variable prints on the page fine, but if i try to bind it here i receive the error. can anyone help?

//CALL FROM PAGE ONE
check($username);

//FUNCTION ON PAGE 2
function check($username){
$DBH = getDBH();
$qSelect = $DBH->prepare("SELECT * FROM users WHERE username = ?");
$qSelect->bind_param("s", $username);
}

我知道这里的功能不是完全写的,但这不应该是一个问题.我不明白为什么会收到此错误.

i know the function is not completely written here, but that shouldn't be a problem. I don't understand why i am receiving this error.

推荐答案

$qSelect似乎不是对象.尝试在准备调用之后立即使用var_dump($qSelect);进行调试.还要检查getDBH()是否返回您需要的内容.

as the error-message says, $qSelect seems to be not an object. try to debug this by using var_dump($qSelect); right after your prepare-call. also check if getDBH() returns what you need.

诸如prepare-call之类的声音失败(不知道为什么),因此它返回false-false不是对象,因此您不能在其上调用bind_param().

sounds like the prepare-call fails (don't know why) and so it returns false - false is not an object, so you can't call bind_param() on that.

编辑:您尚未提供该信息,但似乎您正在使用PHP的PDO.在这种情况下,请查看文档.

you havn't given the info, but it looks like you're using PHP's PDO. In that case, take a look at the documentation.

如果数据库服务器成功 准备语句PDO :: prepare() 返回一个PDOStatement对象.如果 数据库服务器无法成功 准备语句PDO :: prepare() 返回FALSE或发出PDOException (取决于错误处理).

If the database server successfully prepares the statement, PDO::prepare() returns a PDOStatement object. If the database server cannot successfully prepare the statement, PDO::prepare() returns FALSE or emits PDOException (depending on error handling).

您应将服务器配置为返回那些PDO异常,这将告诉您为什么prepare调用失败.

You should configure your server to return those PDO-Exceptions, which would tell you why the prepare call fails.

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

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