0

看过类似的问答,还是不知道,所以不要拍:)

我正在尝试这个:

Array ( [0] => Array ( [id] => 3 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) [1] => Array ( [id] => 4 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) )

$this->db->update_batch('credit_statement', $data, 'id'); 

并返回:

A Database Error Occurred
You must use the "set" method to update an entry.

并觉得我尊重 Codeigniter 书:

$data = array(
   array(
      'title' => 'My title' ,
      'name' => 'My Name 2' ,
      'date' => 'My date 2'
   ),
   array(
      'title' => 'Another title' ,
      'name' => 'Another Name 2' ,
      'date' => 'Another date 2'
   )
);

$this->db->update_batch('mytable', $data, 'title'); 

// Produces: 
// UPDATE `mytable` SET `name` = CASE
// WHEN `title` = 'My title' THEN 'My Name 2'
// WHEN `title` = 'Another title' THEN 'Another Name 2'
// ELSE `name` END,
// `date` = CASE 
// WHEN `title` = 'My title' THEN 'My date 2'
// WHEN `title` = 'Another title' THEN 'Another date 2'
// ELSE `date` END
// WHERE `title` IN ('My title','Another title')

我究竟做错了什么?

4

1 回答 1

3

在 update_batch 方法中调用 $data 变量时,您没有设置它。

改变这个:

Array ( [0] => Array ( [id] => 3 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) [1] => Array ( [id] => 4 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) )

对此:

$data = Array ( [0] => Array ( [id] => 3 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) [1] => Array ( [id] => 4 [paid_date] => 2013-06-25 20:37:35 [statement_status] => P ) );
于 2013-06-26T04:21:33.973 回答