ThinkPHP6.0 数据库数据表查询几种方式

1、单条数据查询 find

find 方法查询结果不存在,返回 null,否则返回结果数组

public function index(){

$find = Db::table('shop_goods')->find(5);

print_r($find);

}

2、多条数据查询 select

select 方法查询结果是一个二维数组,如果结果不存在,返回空数组

public function index(){

$select = Db::table('shop_goods')->select();

print_r($select);

}

3、查询某个字段的值 value

value 方法查询结果不存在,返回 null

public function index(){

$value = Db::table('shop_goods')->value('title');

print_r($value);

}

4、查询某一列的值 column

column 方法查询结果不存在,返回空数组

public function index(){

$column = Db::table('shop_goods')->column('title');

print_r($column);

$column = Db::table('shop_goods')->column('title','id');

print_r($column);

}

文章来自 www.hezhidz.com

posted @ 2021-06-24 10:42  学无边涯  阅读(1266)  评论(0编辑  收藏  举报