tp5 数据模型几种用法

where数组条件

数组方式有两种查询条件类型:关联数组和索引数组。

关联数组

// 传入一维数组作为查询条件
Db::table('think_user')->where([
    'name'	=>	'thinkphp',
    'status'=>	1
])->select(); 

索引数组

// 传入二维数组作为查询条件
Db::table('think_user')->where([
    ['name','=','thinkphp'],
    ['status','=',1]
])->select(); 

// or
$map1 = [
        ['name', 'like', 'thinkphp%'],
        ['title', 'like', '%thinkphp'],
    ];
    
$map2 = [
        ['name', 'like', 'kancloud%'],
        ['title', 'like', '%kancloud'],
    ];    
    
Db::table('think_user')
    ->whereOr([ $map1, $map2 ])
    ->select();

注:
全是= 可用一维数组
大于小于 用二维数组

column指定索引

return self::order('display_order desc,id asc')->cache('admin_ruleMap_path',7200,'admin')->column('*','path');

模型转数组

posted @ 2020-08-07 09:58  王玉岩  阅读(343)  评论(0编辑  收藏  举报