Home Backend Development PHP Tutorial ThinkPHP3.2 framework uses addAll() to insert data in batches

ThinkPHP3.2 framework uses addAll() to insert data in batches

Jun 07, 2018 pm 04:22 PM
addall() thinkphp3.2 batch insert data

This article mainly introduces the method of batch inserting data using addAll() in the ThinkPHP3.2 framework, and analyzes thinkPHP's related implementation skills for single data insertion and batch data insertion operations in the form of examples. Friends in need can refer to the following

The example of this article describes the method of batch inserting data using addAll() in the ThinkPHP3.2 framework. Share it with everyone for your reference, the details are as follows:

The addAll() method of the model class in thinkphp can add data to the database at the same time.

// 批量添加数据 (only MySQL)
$user = M('user');
//array('表字段'=>'值')
$dataList[] = array('name'=>'thinkphp','email'=>'thinkphp@gamil.com');
$dataList[] = array('name'=>'onethink','email'=>'onethink@gamil.com');
$insertOkInfo = $user->addAll($dataList);
Copy after login

The following is the method of inserting a single piece of data

$user = M('demo');
$data['name'] = 'xiaoming';
$data['sex'] = '1';
$data['age'] = '23';
// 使用add()方法将数据写入数据库
// 返回 Id
$insertId = $user->add($data);
Copy after login

There is also a practical methodfilter() ,This method is to filter the field content into text.

The following example:

Convert<b>thinkphp</b> into "thinkphp"

//name字段有html标签
$data[&#39;name&#39;] = &#39;&lt;b&gt;thinkphp&lt;/b&gt;&#39;;
$data[&#39;sex&#39;] = &#39;1&#39;;
$User = M(&#39;demo&#39;);
// 写入数据库的时候会把name字段的值&lt;b&gt;thinkphp&lt;/b&gt;转化为“thinkphp”
$User-&gt;data($data)-&gt;filter(&#39;strip_tags&#39;)-&gt;add();
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Thinkphp5.0's method of automatically generating modules and directories

ThinkPHP framework implements session cross-domain issues

Perfect solution to the problem of inserting the same data in Thinkphp3.2

The above is the detailed content of ThinkPHP3.2 framework uses addAll() to insert data in batches. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Use ddrescue to recover data on Linux Use ddrescue to recover data on Linux Mar 20, 2024 pm 01:37 PM

Use ddrescue to recover data on Linux

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation! Apr 03, 2024 pm 12:04 PM

Open source! Beyond ZoeDepth! DepthFM: Fast and accurate monocular depth estimation!

How to use Excel filter function with multiple conditions How to use Excel filter function with multiple conditions Feb 26, 2024 am 10:19 AM

How to use Excel filter function with multiple conditions

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training Apr 01, 2024 pm 07:46 PM

Google is ecstatic: JAX performance surpasses Pytorch and TensorFlow! It may become the fastest choice for GPU inference training

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks Apr 29, 2024 pm 06:55 PM

The vitality of super intelligence awakens! But with the arrival of self-updating AI, mothers no longer have to worry about data bottlenecks

Slow Cellular Data Internet Speeds on iPhone: Fixes Slow Cellular Data Internet Speeds on iPhone: Fixes May 03, 2024 pm 09:01 PM

Slow Cellular Data Internet Speeds on iPhone: Fixes

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times. May 07, 2024 pm 05:00 PM

The U.S. Air Force showcases its first AI fighter jet with high profile! The minister personally conducted the test drive without interfering during the whole process, and 100,000 lines of code were tested for 21 times.

The first robot to autonomously complete human tasks appears, with five fingers that are flexible and fast, and large models support virtual space training The first robot to autonomously complete human tasks appears, with five fingers that are flexible and fast, and large models support virtual space training Mar 11, 2024 pm 12:10 PM

The first robot to autonomously complete human tasks appears, with five fingers that are flexible and fast, and large models support virtual space training

See all articles