ghost2006n 发表于 2013-6-6 11:33:09

批量更新和批量插入怎么做

如题,批量更新和批量插入怎么做

最爱吃馒头 发表于 2014-7-31 11:48:32

$this->db->insert_batch('mytable', array(array('id'=>1),array('id'=>2));批量插入
批量更新:
$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')

okool 发表于 2014-11-5 20:28:06

最爱吃馒头 发表于 2014-7-31 11:48
$this->db->insert_batch('mytable', array(array('id'=>1),array('id'=>2));批量插入
批量更新:
$data =...

那怎么返回结果和错误呢?


页: [1]
查看完整版本: 批量更新和批量插入怎么做