thinkphp5 saveAll insertAll getLastInsID
								
								
						
	thinkphp5 saveAll insertAll getLastInsID
	批量新增数据,能不能获得最后增加数据的id?
	1,模型方法:
$datas = [];
    $datas[] = ['articleTitle'=>'标题1'];
    $datas[] = ['articleTitle'=&...
							
								Uncaught Error: Call to undefined function mysql_insert_id()
								
								
						
	错误:
	Uncaught Error: Call to undefined function mysql_insert_id()
	原因:
	php版本太高了,php7.4
	mysql_insert_id()改为mysqli_insert_id()
	出现位置:ecshop商城,includes\cls_mys...
							
								tp5,批量添加insertAll,分批插入Db::name('user')->data($data)->limit(100)->insertAll();
								
								
						
	用tp5做excel批量导入的时候,由于数据量很大(6万条),导致提示如下错误:
	The server encountered an internal error or misconfiguration and was unable to complete your request.
	Please contact the ...
							
								Thinkphp6新增数据,并获取主键ID
								
								
						// 方法1:insertGetId方法,新增数据并返回主键值使用getLastInsID
Db::name('user')->insert($data);
	$userId = Db::name('user')->getLastInsID();
	
// 方法2:使用insertGetId方法
	Db::name(...
							
								phpmyadmin insert into导入数据后,数据库中没有数据
								
								
						
	phpmyadmin 导入成功,但是数据库数据为空
	其实主键id的值已经增加了,提示成功,但数据库中没有数据。
	sql语句没问题,直接在sql运行这是可以成功添加数据的。
	
	sql语句文件是导出的zht_privilege.sql改的,改的时候不小心删了
	
	然后,再导入数据,就一直为空了。
	正...
							
								TP5.1 insert添加数据时自动时间戳create_time无效
								
								
						
	平常添加数据一般都用allowField(true)->save(),自动添加时间戳。
但是用insert和insertAll新增数据,create_time和update_time不会自动生成时间戳。
	
	save 是模型方法 会自动写入时间戳
insert 是Db方法 不会自动写入时间戳的
							
								thinkphp5获取新增记录id
								
								
						使用getLastInsID方法:
Db::name('messege')->insert($data);
$userId = Db::name('messege')->getLastInsID();
使用insertGetId方法
$userId = Db::name('messege')->insertGetId(...
							
								一条insert语句批量插入多条记录
								
								
						
	一条语句只能插入一条数据:
insert into persons 
(id_p, lastname , firstName, city )
values(204,'haha' , 'deng' , 'shenzhen');
怎样一次insert插入多条记录:
insert into persons 
(id_p, lastn...
							
								jquery控制div的显示位置,显示顺序
								
								
						
	在做网页手机端pc端自适应的时候,我们希望pc端,a模块在前,b模块在后。
	当屏幕缩小,换成移动端的时候,我们希望b模块在前,a模块在后。
	怎么实现呢,通过jquery实现。
	html代码:
<div class="content_left">
                	上边
        ...
							
								thinkphp5.1添加数据
								
								
						<?php
namespace app\index\model;
use think\Db;
class Articles
{
	/**
	 * 添加一条数据
	 * insert 方法添加数据成功返回添加成功的条数,通常情况返回 1
	 */
	public function insert(){
		$data = ['arti...
							
								insertAll_批量添加
								
								
						
	这里只是拷贝一下手册代码,详情请查看手册
<?php
namespace app\index\controller;
use think\Db;
class Index {
    public function index(){ 
    	
    	// 1.创建员工信息数组
    	$data = [];
    ...
							关于本站
	
	“最难不过坚持”
本人承接扒站仿站,php网站维护,病毒查杀,网站编辑,网站改版,html制作
有需要网站维护,改版,病毒查杀,网站编辑,网站备案,html制作等相关的工作可以联系我。
本人有多年相关工作经验,也可提供免费咨询,交个朋友。
有需要探讨问题的朋友,也可以加我微信,共同探讨!
微信:15011482830 QQ:408917339
		
		 2712
		 39
	
分类目录
	最新评论
	- https://jueru.net/
- 
			评 留言  
- :weixiao:
- 
			评 留言  
- :shuijiao: :weiqu: :zhenbang: :leng:
- 
			评 留言  
- :yiwen: :yiwen: :yiwen: :yiwen:
- 
			评 EasySass: could not generate CSS file. See Output panel for details.  
- 这个业务逻辑多少都有点奇怪了,阅读浏览次数增值在新闻详情页的控制器方法里setInc,这怎么还写进模型事件里了。如果非要用onAfterRead也可以,把新闻文章的内容单独分出来一个news_content表,然后把它和news做关联,然后给news_content表的onAfterRead事件做增值处理,这样点进新闻页内查询到文章内容时才会触发它。
- 
			评 TP6模型事件-查询后onAfterRead不好用  
文章标签更多 
	
