当前位置: 编程技术>php
php CI框架插入一条或多条sql记录示例
来源: 互联网 发布时间:2014-08-26
本文导语: 1、插入一条记录 $data = array( 'title' => 'My title' , 'name' => 'My Name' , 'date' => 'My date' ); $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') 2、插入多条记录 $data = array( arr...
1、插入一条记录
$data = array( 'title' => 'My title' , 'name' => 'My Name' , 'date' => 'My date' ); $this->db->insert('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date')
2、插入多条记录
$data = array( array( 'title' => 'My title' , 'name' => 'My Name' , 'date' => 'My date' ), array( 'title' => 'My title1' , 'name' => 'My Name1' , 'date' => 'My date1' ) ); $this->db->insert_batch('mytable', $data); // Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'),('My title1', 'My name1', 'My date1')