This article mainly introduces the ThinkPHP3.2 framework using AddAll () Bulk Insert data method, combined with the example form analysis of thinkphp for single data insertion and bulk data insertion operation of the relevant implementation skills, the need for friends can refer to the next
This example describes how the ThinkPHP3.2 framework uses AddAll () to insert data in bulk. Share to everyone for your reference, as follows:
The method of the model class in thinkphp addAll()
can add data to the database at the same time.
Bulk 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);
Here's how to insert a single piece of data
$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 way filter()
to filter the contents of a field into text.
Here's an example:
Convert <b>thinkphp</b> to "thinkphp"
The Name field has an HTML tag $data[' name '] = ' <b>thinkphp</b> '; $data [' sex '] = ' 1 '; $User = M (' demo ');// When writing to the database, the value of the Name field is converted to "thinkphp" $User->data ($data)->filter (' Strip_tags ') Add ();
Related articles:
About thinkphp How to write your own functions and classes, where to put them, how to call them, ask for advice
Thinkphp sample code for simple call functions and class library methods
thinkphp database additions and deletions to the operation Method Example detailed