2013-04-15 69 views
0

我想做一個簡單的更新,我將一個數組從控制器傳遞給模型。不過,我收到以下錯誤:Codeigniter有效記錄更新 - 錯誤

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 'id #29 

這裏是正在傳遞的數組:

<? 
$data = Array 
    (
    [name] => last_name 
    [value] => Smith 
    [pk] => 611 
); 

控制器

<? 
function edit_client() { 
    $data = $this->input->post(); 
    $this->load->model('clients_model'); 
    $this->clients_model->update_client_info($data); 
} 

模型

<? 
function update_client_info($data) { 
    $update = $this->db->set($data['name'], $data['value']); 
    $this->db->where('id', $data['pk']); 
    $this->db->update('clients', $update); 
} 

任何想法我在這裏做錯了嗎?

回答

1

問題在於你的$this->db->set()函數。

執行以下操作

$this->db->set('name',$data['name']); 
$this->db->set('value',$data['value']); 
$this->db->where('id', $data['pk']); 
$this->db->update('clients'); 

這應該做的伎倆。 當您使用$this->db->set()時,不需要將表名以外的任何其他內容傳遞給插入或更新函數。