Home >Backend Development >PHP Tutorial >CI framework AR operation (array form) to implement the method of inserting multiple sql data, ciar_PHP tutorial
This article describes the CI framework AR operation method of inserting multiple sql data. Share it with everyone for your reference, the details are as follows:
If you don’t use AR, you can do this:
INSERT INTO TABLE (FIELDS) VALUES ('1','2'),('3','4'); $this->db->query($sql);
Personally, I still like the AR operation of CI. The old version (2.0 or below) should not have the operation of inserting multiple pieces of data. The new version can be used:
$this->db->insert_batch();
The following cases:
$data = array( array( 'name' => 'PHP' , 'url' => 'http://www.bkjia.com' ), array( 'name' => '帮客之家' , 'url' => 'http://www.bkjia.com' ) ); $this->db->insert_batch('mytable', $data);
The sql generated above is like this:
Copy code The code is as follows: INSERT INTO mytable (name, url) VALUES ('PHP','http://www.bkjia.com'),( 'Bangkejia ', 'http://www.bkjia.com')
Summary: The data parameters in the database shortcut operation class in the ci framework are generally one-dimensional associative arrays .
Readers who are interested in more CodeIgniter related content can check out the special topics of this site: "codeigniter introductory tutorial", "CI (CodeIgniter) framework advanced tutorial", "php excellent development framework summary", "ThinkPHP introductory tutorial", "Summary of Common Methods in ThinkPHP", "Introduction Tutorial on Zend FrameWork Framework", "Introduction Tutorial on PHP Object-Oriented Programming", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone’s PHP program design based on the CodeIgniter framework.