ci模型上的语法错误

时间:2014-06-20 12:03:53

标签: php codeigniter

由于某种原因,我在使用codeigniter插入查询时出现了一个小问题,即syntax error check the manual that corresponds to your MySQL server version。我以为我做的每一件事看起来都不错,但不确定。

我认为可以这样做。

public function database() {
$data['db_prefix'] = $this->db->dbprefix; $data['username'] = $this->input->post('username'); $data['email'] = $this->input->post('email'); $data['password'] = $this->input->post('password'); 

$this->db->query("DELETE FROM `" . $data['db_prefix'] . "user` WHERE user_id = '1'");

$this->db->query("INSERT INTO `" . $data['db_prefix'] . "user` SET user_id = '1', user_group_id = '1', username = '" . $this->db->escape($data['username']) . "', salt = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', password = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', status = '1', email = '" . $this->db->escape($data['email']) . "', date_added = NOW()");
} 

1 个答案:

答案 0 :(得分:0)

status是MySQL http://dev.mysql.com/doc/refman/5.1/en/show-status.html

中的保留字

使用``

status查询中包装INSERT
$this->db->query("
    INSERT INTO 
       `" . $data['db_prefix'] . "user` 
    SET 
         user_id       = '1', 
         user_group_id = '1', 
         username      = '" . $this->db->escape($data['username']) . "',  
         salt          = '" . $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)) . "', 
         password      = '" . $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))) . "', 

         `status`      = '1', 

         email         = '" . $this->db->escape($data['email']) . "', 
         date_added    = NOW()

");