Correcting teacher:天蓬老师
Correction status:qualified
Teacher's comments:继续努力
# 返回结果集
$res = DB::select( 'select * from posts where id>:id', ['id'=>25] );
# 返回bool值
$res = DB::insert( 'insert into posts(`title`,`content`) values(?,?)' ,["世界最长...","中新社福州12月22日电..."]);
# 返回受影响数
$res = DB::update( 'update posts set updated_at=? where id=28',[date('Y-m-d h:m:s',time())] );
# 返回受影响数
$res = DB::delete( 'delete from posts where id=?',[30] );
# 返回结果集
$res = DB::table('zans')->get()->toArray();
# 返回bool值
$res = DB::table('zans')->insert( ['user_id'=>6, 'post_id'=>28] );
# 返回受影响数
$res = DB::table('zans')->where('id',8)->update( ['created_at'=>date('Y-m-d h:m:s',time())] );
# 返回受影响数
$res = DB::table('zans')->where('id',11)->delete();
ps: 查询构造器里的select()是指定查询的列,DB facade原始查询里select()就是查询方法
# 查询 id=19 的记录
$res = DB::table('posts')->where( 'id', 19 )->get()->toArray();
# 查询 id between (25,27) 的记录
$res = DB::table('posts')->whereBetween( 'id', [25,27] )->get()->toArray();
# 查询 id in (19,27) 的记录
$res = DB::table('posts')->whereIn('id', [19,27])->get()->toArray();
# 查询 id=27 or id=25 的记录
$res = DB::table('posts')->orWhere('id',27)->orWhere('id',25)->get()->toArray();
# 插入一条记录,返回bool值
$res = DB::table('zans')->insert(['user_id'=>6,'post_id'=>28]);
# 插入多条记录,返回bool值
$res = DB::table('zans')->insert([['user_id'=>6,'post_id'=>19],['user_id'=>3,'post_id'=>28]]);
# 插入一条记录,返回新增记录的id值
$res = DB::table('zans')->insertGetId(['user_id'=>1,'post_id'=>23]);
ps: insert和insertGetId方法异同:
同:都是插入数据
异:insert可插入多条,insertGetId只能插入一条;在插入一条记录时,insert返回bool值,insertGetId返回新增记录的id值