- AR operations using the CI Framework: insert_batch () can reduce the number of times a database is accessed. One visit.
Example 1:
$dataanarray ('title ' + ' My title ', ' name ' = ' my ' Name ', ' date ' = ' My date ' ), array( ' title ' = ' Another ') Title ', ' name ' = ' Another name ', ' date ' = ' another date ') ; $this $data // generate: INSERT into MyTable (title, name, date) VALUES (' My title ', ' My Name ', ' My Date '), (' Anot Her title ', ' Another name ', ' another date ')
Example 2:
$one _info=Array();$insert _data=Array();$one _info[' role_id '] = 6;$one _info[' operator '] = ' test '; for($i= 0;$i<= 3;$i++) { $one _info[' net_id '] = $i; $insert _data[] =$one _info;}if(!$this->db->insert_batch (TableA,$insert _data)) { return3; }
The inserted SQL statement is insert INTO TableA (role_id,operator,net_id) VALUES (6, ' test ', 0), (6, ' Test ', 1), (6, ' Test ', 2);
Note: The first parameter contains the table name, and the second is an associative array that contains the data.
CI Framework database BULK INSERT Insert_batch ()