【发布时间】:2017-07-21 20:51:55
【问题描述】:
我正在开发用户登录功能,但遇到了一个奇怪的问题“列数无效”。我用谷歌搜索了它,很多人都有同样的问题,他们的问题有点不同。
这是我的代码:
//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();
}
注册查询有效,但这会引发异常。我知道,会有一个小错误,但我花了一整天都想不通。
我们将不胜感激!
【问题讨论】:
-
我唯一的建议是尝试
bindParam(带大写“P”)而不是bindparam。其他一切对我来说都是正确的。 -
肯定是 pdo 而不是 mysqli?
-
你有 3 个占位符和 2 个绑定......想知道“无效的列数”来自哪里。
-
@YvesLeBorg 这是另一回事,但 OP 似乎通过不回复之前发布的其他 cmets 离开了这个问题。所以,我认为我什至提到另一个最有可能的可能性对我来说没有多大意义。
-
检查您的 php 系统文件以查看是否设置了仿真。如果不是,您既不会打开它也不会重命名重复的占位符名称之一。这就是您收到该错误的原因@Alena