Share ThinkPHP3.2 using addAll () to insert data in batches

Source: Internet
Author: User
Tags addall
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!

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.