ThinkPHP3.2 Framework uses AddAll () to BULK INSERT data

Source: Internet
Author: User
Tags addall bulk insert
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 ();

The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.