This article mainly introduces the method of using addAll () to insert data in batch in the ThinkPHP3.2 framework, and analyzes thinkPHP's implementation skills for single data insertion and batch data insertion in combination with the instance form, for more information about how to use addAll () in the ThinkPHP3.2 framework to insert data in batches, this article analyzes thinkPHP's implementation skills for single data insertion and batch data insertion in combination with the instance form. For more information, see
This example describes how to use addAll () to insert data in batches in the ThinkPHP3.2 framework. We will share this with you for your reference. The details are as follows:
Model class in thinkphpaddAll()
You can add data to the database at the same time.
// Batch add data (only MySQL) $ user = M ('user'); // array ('Table field' => 'value ') $ dataList [] = array ('name' => 'thinkphp', 'Email '=> 'thinkphp @ gamil.com '); $ dataList [] = array ('name' => 'onethink ', 'Email' => 'onethink @ gamil.com '); $ insertOkInfo = $ user-> addAll ($ dataList );
The following describes how to insert a single data record.
$ User = M ('demo'); $ data ['name'] = 'xiaoming'; $ data ['sex'] = '1 '; $ data ['age'] = '23'; // use the add () method to write data to the database // return Id $ insertId = $ user-> add ($ data );
There is also a practical methodfilter()
This method filters the field content into text.
Example:
SetThinkphpConvert to "thinkphp"
// The name field has an html tag $ data ['name'] ='Thinkphp'; $ Data ['sex'] = '1'; $ User = M ('demo'); // when writing data to the database, the value of the name field isThinkphpConvert to "thinkphp" $ User-> data ($ data)-> filter ('strip _ tags')-> add ();
Related articles:
How to write your own functions and classes in thinkphp, and how to call them?
Example code of thinkPHP simple function call and class library method
Details about how to add, delete, modify, and query operations for the thinkPHP database
The preceding content is shared by the ThinkPHP3.2 framework using addAll () to insert data in batches. For more information, see other related articles in the first PHP community!