批改状态:未批改
老师批语:
数据库原生查询的实现方法
2. 数据库闭包查询
3. 练习课程中未演示的其它链式方法;
<?php
namespace app\index\controller;
use think\console\Table;
use think\Db;
use think\db\Query;
class demo1
{
//数据库原生查询的实现方法
public function list1(){
$res = Db::query('select * from user where id=:id',['id'=>4]);
dump($res);
}
//数据库闭包查询
public function list2(){
$res = Db::select(function ($query){
$query->table('user')->where('id',4);
});
dump($res);
}
//练习课程中未演示的其它链式方法
public function list(){
$res = Db::table('user')
->where('id','=',4)
->find();
if ($res){
echo '<h1 style="color: rebeccapurple;">成功了</h1>';
dump($res);
}
}
public function update(){
$num = Db::table('user')
->where('id',4)
->data(['salary'=>5555])
->update();
if ($num){
echo '<h2>更新成功</h2>';
$res = Db::table('user')
->field(['id'=>'编号','name'=>'姓名','salary'=>'工资'])
->where('id',4)
->find();
dump($res);
}
}
}点击 "运行实例" 按钮查看在线实例

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号