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

一、insert()成功返回受影响条数,失败返回false;

<?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 insert(){
		$data = [
			'name' => '张三',
			'email' => 'zs@qq.com',
			'course' => 'php',
			'grade' => 95
		];
		return  Db::table('student')->insert($data);
		// 插入的同时返回新增的主键ID 使用 insertGetId()方法
		// insertGetId() 同时执行两步操作,1、插入数据,2、返回新增的主键ID
		// return Db::table('student')->insertGetId($data);

	}
}


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