批改状态:未批改
老师批语:
<?php
namespace app\index\controller;
use think\Db;
class Homework0524
{
public function demo()
{
$res = Db::table('staff')
->field(['name'=>'姓名', 'sex'=>'性别', 'salary'=>'工资'])
->where('salary','>',3000)
->limit(6)
->order('salary', 'DESC')
->select();
dump($res);
}
public function insert()
{
// $data = [
// 'name' => '归海一刀',
// 'sex' => 0,
// 'salary' => 6600,
// 'age' => 38
// ];
// $num = Db::table('staff')->data($data)->insert();
// return $num ? '增加成功,id是'.Db::getLastInsID() : '没有数据被增加';
$data2 = [
['name'=>'吕布','sex'=>0,'age'=>32,'salary'=>8900],
['name'=>'貂蝉','sex'=>1,'age'=>26,'salary'=>7300],
['name'=>'甄宓','sex'=>1,'age'=>22,'salary'=>4600],
];
$num2 = Db::table('staff')->data($data2)->insertAll();
return $num2 ? '成功增加'.$num2.'条数据' : '没有数据被增加';
}
public function update()
{
$num = Db::table('staff')
->where('staff_id', 9)
->data(['salary'=> Db::raw('salary+1500')])
->update();
return $num ? '更新成功,添加了'.$num.'条记录' : '没有记录被更新';
}
public function delete()
{
$num = Db::table('staff')
->where('staff_id', 9)
->delete();
return $num ? '删除成功,添加了'.$num.'条记录' : '没有记录被删除';
}
}点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号