insert() save()增加数据的区别---ThinkPH

2018-12-14  本文已影响0人  思议岁月

插入数据简单颜色

成功新增实例

插入成功案列

$t3=T::insert(['t'=>500]);
      $t8=Db::table('t')->insert(['t'=>700]);
        $t4=model('t');
        $t4->t=800;
        $t4=$t4->save();
        $t5=new T();
        $t5->t=900;
        $t5= $t5->insert();//此条插入失败

···
返回值
{
"t3": 1,
"t4": true,
"t5": 0,
"t8": 1
}
···

2报错列表

$t1=T::save(['t'=>300]);//报Non-static method think\Model::save() should not be called statically
$t5=Db::table('t')->save(['t'=>300]);//报method not exist:think\db\Query->save
$t2=T::insert('t=400');//类型错误: Argument 1 passed to think\db\Query::insert() must be of the type array, string given
$t7=Db::table('t')->insert('t=600');//Argument 1 passed to think\db\Query::insert() must be of the type array, string given, called in 
上一篇下一篇

猜你喜欢

热点阅读