Max*_*Max 29 activerecord codeigniter codeigniter-2
可以在CodeIgniter Active Record中使用多个INSERT记录而不使用forach,foreach等?
我目前的代码:
foreach($tags as $tag) {
$tag = trim($tag);
$data = array(
'topic_id' => $topic_id,
'user_id' => $user_id,
'text' => $tag
);
$this->db->insert('topic_tags', $data);
}
Run Code Online (Sandbox Code Playgroud)
tom*_*ans 69
Codeigniter活动记录具有insert_batch
我认为您需要的功能
$data = array(
array(
'title' => 'My title' ,
'name' => 'My Name' ,
'date' => 'My date'
),
array(
'title' => 'Another title' ,
'name' => 'Another Name' ,
'date' => 'Another date'
)
);
$this->db->insert_batch('mytable', $data);
// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')
Run Code Online (Sandbox Code Playgroud)
适用于Codeigniter 3.x和Codeigniter 2.2.6
更新的链接
Codeigniter 3.x的insert_batch()
Codeigniter 2.x的insert_batch()
归档时间: |
|
查看次数: |
43279 次 |
最近记录: |