我正忙着将CodeIgniter从2.1.4升级到3.0.1,并按照此处的说明进行操作:http://www.codeigniter.com/userguide3/installation/upgrade_300.html
自从我开始以来,我收到了这个错误:
Error Number: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? AND `password` = ?' at line 3
以下是完整的查询:
$sql = "
SELECT *
FROM `icms4_user`
WHERE `username` = ?
AND `password` = ?
";
似乎升级现在导致数据库类拒绝用适当的值替换问号占位符。
查询代码如下所示:
$q = $this->db->query($sql, array($user, $pass));
任何人都知道导致这种情况的原因是什么?
答案 0 :(得分:0)
例如我刚刚为数据库信息创建了一个测试用户控制器和一个测试函数,并注意到我目前只有" . '?' . "
我只是将电子邮件而不是密码放在了例如
Var转储显示正常工作
array(4) { ["user_id"]=> string(1) "2" ["user_group_id"]=> string(2) "10" ["username"]=> string(4) "demo" ["email"]=> string(13) "demo@demo.com" } 2
控制器示例
<?php
class Users extends CI_Controller {
public function index() {
// Example Only
// hard code in just for testing
$username = 'demo';
$email = 'demo@demo.com';
$user_info = $this->test($username, $email);
var_dump($user_info);
// Echo Test Data
echo $user_info['user_id'];
echo '</br>';
echo $user_info['user_group_id'];
echo '</br>';
echo $user_info['username'];
}
public function test($username, $email) {
$sql = "SELECT * FROM " . $this->db->dbprefix . "user
WHERE username = " . '?' . "
AND email = " . '?' . "
";
$query = $this->db->query($sql, array($username, $email));
return $query->row_array();
}
}
答案 1 :(得分:0)
在我的config.php文件中进行一些更改后,问题就消失了。我(我很傻)在我的config.php中使用db_prefix而不是我的database.php文件,并配置错误。