一、多条数据查询select()方法,返回的是一个二维数组,如果没有数据返回的是空数组。
二、对多条数据进行查询的结果集,需要进行遍历才可以拿到。
<?php
namespace app\index\controller;
use think\Db;
/*
查询构造器
准备工作:app_debug = true; app_trace = true;
*/
class Index{
public function index(){
return Db::table('student')
->where('id',1)
->value('name');
}
public function select(){
$res = Db::table('student')
->field('id,name,course,grade') //指定查询字段
->where([
['course','=','php'],
['grade','>=',86]
])
->select();
if (empty($res)){
return '没有找到符合条件的记录';
}else{
//对多条数据进行查询的结果集,需要进行遍历才可以拿到
foreach ($res as $row) {
dump($row);
}
}
}
}
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号