简体   繁体   English

Codeigniter活动记录更新-错误

[英]Codeigniter Active Record Update - Error

I am trying to do a simple update where I pass an array from the Controller to the Model. 我试图做一个简单的更新,我将一个数组从控制器传递给模型。 But I am getting the following error: 但是我收到以下错误:

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

Here is the array that is being passed: 这是要传递的数组:

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

CONTROLLER 控制器

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

MODEL 模型

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

Any ideas what I'm doing wrong here? 有任何想法我在这里做错了吗?

The problem is in your $this->db->set() function. 问题出在您的$this->db->set()函数中。

Do the following 请执行下列操作

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

That should do the trick. 这应该够了吧。 When you use the $this->db->set() , you need not pass anything other than the table name to the insert or update functions. 使用$this->db->set() ,无需将表名称以外的任何内容传递给insert或update函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM