Home >Backend Development >PHP Tutorial >CI framework AR operation (array form) to implement the method of inserting multiple sql data, ciar_PHP tutorial

CI framework AR operation (array form) to implement the method of inserting multiple sql data, ciar_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:52:151012browse

CI framework AR operation (array form) realizes the method of inserting multiple sql data, ciar

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1127856.htmlTechArticleCI framework AR operation (array form) implements the method of inserting multiple sql data, ciar This article describes the CI framework with examples AR operation implements the method of inserting multiple sql data. Sharing it with everyone for your reference,...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn