use Illuminate\Support\Facades\DB;
//引入数据库类
public function user(){
var_dump(‘aaa‘);
$arr = [
‘title‘=>‘aaaa‘,
‘descs‘=>‘bbbb‘
];
DB::table(‘new‘)->insert([$arr]);
//可以同时增加一条或多条,返回值是布尔类型;
$arr1 = [
[‘title‘=>‘aaaa‘,‘descs‘=>‘bbbb‘],
[‘title‘=>‘cc‘,‘descs‘=>‘dd‘]
];
$id = DB::table(‘new‘)->insertGetId($arr);
var_dump($id);
//只能增加一条数据,返回自增ID;
$a = [‘title‘=>‘123‘];
$ids = DB::table(‘new‘)->where(‘id‘,4)->update($a);
var_dump($ids);
//更新所有的字段,返回值为受到影响的行数;
DB::table(‘basgame‘)->increment(‘time‘);
//只是修改某个字段自增
$b = DB::table(‘new‘)->get();
foreach($b as $val){
echo $val->id."<br>";
}
//$b为取出的基本数据,再通过foreach循环查找的数据
$a1 = DB::table(‘basgame‘)->where(‘id‘,29)->select(‘team1‘,‘team2‘)->get();
//获取某些字段的值
$a2 = DB::table(‘basgame‘)->where(‘id‘,27)->value(‘team1‘);
//取出某一行的某一个值
$a3 = DB::table(‘basgame‘)->first();
//取单行所有数据
var_dump($a3);
$a4 = DB::table(‘scogame as a‘)->where(‘a.contest‘,‘西甲‘)->join(‘gameguess as b‘,‘a.gid‘,‘=‘,‘b.gid‘)->get();
var_dump($a4);
//laravel框架的多表联合查询写法,‘a.gid‘,‘=‘,‘b.gid‘与tp5不同
DB::table(‘basgame‘)->where(‘id‘,24)->delete();
//删除指定数据
DB::table(‘xy_product‘)->truncate();
//删除数据表中所有数据
$a5 = DB::table(‘basgame‘)->orderBy(‘gid‘,‘desc‘)->limit(‘3‘)->offset(1)->select(‘team1‘,‘team2‘,‘time‘,‘gid‘)->get();
var_dump($a5);
//排序和分页,排序orderBy(‘name‘,‘desc‘),分页limit指一页显示几条数据,offset(n)指从第n+1条数据开始
}