Php SQLSTATE[HY093]:参数编号无效-PDO Select语句
我正在开发一个用户登录功能,面临一个奇怪的问题“列数无效”。我用谷歌搜索过,很多人都有同样的问题,他们的问题有点不同 这是我的密码:Php SQLSTATE[HY093]:参数编号无效-PDO Select语句,php,mysql,pdo,Php,Mysql,Pdo,我正在开发一个用户登录功能,面临一个奇怪的问题“列数无效”。我用谷歌搜索过,很多人都有同样的问题,他们的问题有点不同 这是我的密码: //this is a function inside user class. And function receives $user_data array try{ $stmt = $this->db_connection->prepare("SELECT `id` FROM `aaa_users` WHERE (`user_email`
//this is a function inside user class. And function receives $user_data array
try{
$stmt = $this->db_connection->prepare("SELECT `id` FROM `aaa_users` WHERE (`user_email` = :user_email OR `user_name` = :user_email) AND `user_pass` = :user_pass");
$stmt->bindparam(':user_email', $user_data['email']);
$stmt->bindparam(':user_pass', $user_data['password']);
$stmt->execute();
$count = $stmt->rowCount();
} catch (PDOException $e){
echo $e->getMessage();
}
注册查询可以工作,但会引发异常。我知道,可能会有一个小小的错误,但我已经花了一整天的时间,无法找出它
非常感谢您的帮助 正如我在评论中提到的,您的服务器上可能没有启用PDO模拟,并且使用相同的命名占位符(可能是)会导致此错误 我分别将
:user\u mail
重命名为:user\u email\u 1
和:user\u email\u 2
$stmt = $this->db_connection->prepare("
SELECT `id` FROM `aaa_users`
WHERE (`user_email` = :user_email_1
OR `user_name` = :user_email_2)
AND `user_pass` = :user_pass
");
$stmt->bindparam(':user_email_1', $user_data['email']);
$stmt->bindparam(':user_email_2', $user_data['email']);
$stmt->bindparam(':user_pass', $user_data['password']);
$stmt->execute();
您可以在以下有关堆栈的问答中了解更多信息:
$user\u data['X\u values']
相关的所有值都包含值。这表明它可能来自上一个查询,其来源/值未知
如果在测试过程中尚未使用以下链接,请通过以下链接使用错误检查:
另一件事;过去曾经发生过这样的情况,人们实际上不得不在驼峰式中使用
bindParam
,而不是在小写中使用bindParam
;这是可能的。我唯一的建议是尝试(大写字母“p”)而不是bindparam
。我觉得其他一切都很好。肯定是pdo而不是mysqli?你有3个占位符和2个绑定。。。想知道“无效列数”是从哪里来的。@YvesLeBorg这是另外一回事,但OP似乎因为没有回应之前发布的其他评论而离开了这个问题。因此,我认为我甚至不太可能提及其他最可能的可能性。检查您的php系统文件,看看是否设置了模拟。如果不是,则您既不需要打开它,也不需要重命名其中一个重复的占位符名称。这就是为什么你会在@AlenaThank you@Fred-ii-上出现错误的原因,问题是因为使用了相同的占位符。:)非常欢迎@Alena我很高兴看到问题解决了,干杯:-)