addAll($data, array(),true)"."/> addAll($data, array(),true)".">

Home >PHP Framework >ThinkPHP >How to use thinkphp addall method

How to use thinkphp addall method

藏色散人
藏色散人Original
2022-12-13 09:30:341893browse

thinkphp addall method is a method provided by thinkphp for batch operations on data. This method is located in "Library/Think/Model.class.php", and its correct usage syntax is "$user- >addAll($data,array(),true)".

How to use thinkphp addall method

The operating environment of this tutorial: Windows 7 system, ThinkPHP version 5, Dell G3 computer.

How to use thinkphp addall method correctly?

In-depth analysis of the addAll() method in thinkPHP!

Cause:

In the process of pushing system messages, I encountered a problem of batch pushing system messages to tens of thousands of users. What I first thought of was loop insertion. , but immediately rejected it. It is a big taboo for database developers to operate loop operations, so I searched the manual and found the data writing and saw the batch operation: addAll(). The test was successful and I thought everything was fine. However, when the second operation was performed, it prompted a failure. Looking for the reason, it turned out that the data already existing in the database was not overwritten by addAll(), which caused the error!

Solution:

Look for the Thinkphp source code and go to Library/Think/Model.class.php to find the addAll method: public function addAll($dataList,$options= array(),$replace=false) and I understood in a second. replace must ask you whether to overwrite existing data, so I modified my addAll method to: $user->addAll($data,array(),true) :Test again to solve the problem.

Recommended learning: "thinkPHP Video Tutorial"

The above is the detailed content of How to use thinkphp addall method. For more information, please follow other related articles on the PHP Chinese website!

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