无法在准备好的语句中比较来自 mysql 的值
我似乎无法让它连接到数据库,以便我可以运行我准备好的语句。有人知道我忘记了什么吗?
private function check_credentials($plain_username, $password)
{
global $dbcon;
$ac = new ac();
$ac->dbconnect();
$userid = $dbcon->prepare('SELECT id FROM users WHERE username = :username AND password = :password LIMIT 1');
$userid->bindParam(':username', $plain_username);
$userid->bindParam(':password', $password);
$userid->execute();
$id = $userid->fetch();
Return $id;
}
编辑:我将 SQL 查询从 SELECT FROM 查询更改为 INSERT INTO 查询,并且它有效。到底是怎么回事?
I can't seem to get this to connect to the database so that I can run my prepared statement. Does anybody have an idea what I've forgotten?
private function check_credentials($plain_username, $password)
{
global $dbcon;
$ac = new ac();
$ac->dbconnect();
$userid = $dbcon->prepare('SELECT id FROM users WHERE username = :username AND password = :password LIMIT 1');
$userid->bindParam(':username', $plain_username);
$userid->bindParam(':password', $password);
$userid->execute();
$id = $userid->fetch();
Return $id;
}
EDIT: I changed the SQL query from a SELECT FROM query, to an INSERT INTO query and it worked. WHat the heck is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
重新格式化堆栈回溯:
您在 check_credentials 函数中实例化新的
ac
对象有什么原因吗?鉴于 check_credentials 已经是 ac 的方法,这看起来很奇怪。dbconnect
是否会覆盖全局dbcon
?Reformatting your stack backtrace:
Is there any reason you're instantiating a new
ac
object in the check_credentials function? Given that check_credentials is already a method ofac
, this seems odd. Doesdbconnect
overwrite the globaldbcon
?