thinkPHP5.0使用模型查询数据之get()

当参数为数组的时候

Data是模型里面类的名字,是模型文件的名字,也是表的名字

public function test()
{
//$res = $this->data->getMenu();
$model = new Data();
//$data = $this->data->getMenu();
$res = Data::get([
'id' => ['>', 11],
'typeid' => ['BETWEEN', [16, 19]],
]);
dump($res);
}
//生成的SQL语句:
select * from `bbs_Data` where `id`>11 AND `typeid` BETWEEN 16 AND 19 LIMIT 1;
 
 
column()函数
public function test()
{
//$res = $this->data->getMenu();
$model = new Data();
//获取数据字段为node_name的所有数据
$res = Data::column('node_name');
//获取id为11的字段node_name的数据
$res = Data::column('node_name', '11');
//11 => string '产品分类'
dump($res);
}
 
 
value()获取单个字段的值
public function test()
{
//$res = $this->data->getMenu();
$model = new Data();
//value获取单个字段的值
$res = Data::where('id', 11)->value('node_name');
//193:string '系统管理'
dump($res);
}

猜你喜欢

转载自www.cnblogs.com/ymdphp/p/10949447.html