Blogger Information
Blog 14
fans 1
comment 0
visits 25819
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Thinkphp5.1数据库增删改查操作——多条插入insert()
centcool的博客
Original
2662 people have browsed it

插入多条数据 使用 insertAll()方法,添加数据成功返回添加成功的条数

<?php
namespace app\index\controller;
use think\Db;

/*
	查询构造器
	准备工作:app_debug = true; app_trace = true;
*/

class Index{

	public function index(){
		return Db::table('student')
			->where('id',1)
			->value('name');		
	}
	public function insertAll(){
		$data = [
			['name'=>'King','email'=>'a.qq.com','course'=>'html','grade'=>80],
			['name'=>'Jack','email'=>'j.qq.com','course'=>'js','grade'=>60],
			['name'=>'Black','email'=>'b.qq.com','course'=>'php','grade'=>70]
		];
		return Db::table('student')->insertAll($data);
		//返回结果为“3”
	}
}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post