Home >Backend Development >PHP Tutorial >A brief analysis of the maximum data amount supported by THINKPHP's addAll, thinkphpaddall_PHP tutorial

A brief analysis of the maximum data amount supported by THINKPHP's addAll, thinkphpaddall_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:07:54736browse

A brief analysis of the maximum data amount supported by THINKPHP's addAll, thinkphpaddall

There are two methods for Model operation in Thinkphp: add() and addAll

Copy code The code is as follows:

$User = M("User"); // Instantiate User object
$data['name'] = 'ThinkPHP';
$data['email'] = 'ThinkPHP@gmail.com';
$User->add($data);
$dataList[] = array('name'=>'thinkphp','email'=>'thinkphp@gamil.com');
$dataList[] = array('name'=>'onethink','email'=>'onethink@gamil.com');
$User->addAll($dataList);

The addAll method can add data in batches, which is how MySQL is used:

Copy code The code is as follows:

INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);

When the amount of data is large, try to insert in batches instead of inserting items one by one in a loop, otherwise your database will be overwhelmed and hang up.

However, if you take it for granted and store all the data into an array and perform addAll, you will also face a hang-up situation. Why is this?

The reason is that the configuration of the max_allowed_packet variable in mysql limits the length of the upload sql statement. Just configure it to be larger in the mysql configuration

max_allowed_packet = 100M

At the same time, when inserting data, also limit the length of batch insertion. After all, you never know when the data will become millions.

The above is the entire content of this article, I hope you guys will like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/953156.htmlTechArticleA brief analysis of the maximum amount of data supported by THINKPHP's addAll, thinkphpaddall There are two methods for Model operation in Thinkphp: add( ) and addAll copy the code as follows: $User = M("User"); // Instantiate U...
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