tp5 model controlle sql

时间:2024-01-15 15:44:44

model::::
use think\Db 引用db库类 用于数据库之类
use think\Model 引用模板
use think\Cookie 引用传值

$rs=Db::name(‘表名’)->where()->select();
Cookie::get(‘传值’);

controller::::
use think\Db;
use think\Controller;
use think\Cookie;
use app\agency\model\Product as aaa; 引用的model
use app\agency\model\User as usercontroller;

$this->Product = new aaa();
$aa=$this->User=new usercontroller();
$bb=$aa->方法();

sql:
where模糊查询
where(“id”,”like”,”%1″)
$update=db(表名)->where(条件)->update(内容);
$find=db(表名)->where(条件)->find();
$select=db(表名)->where(条件)->select();
$result = db(表名)->insert(内容);

$detale=db(表名)->where(条件)->detele();

多表查询
$rs=Db::name(‘表名 as a,表名 as b’)->field(‘a.字段 ,b.字段’)->where(‘a.条件=b.条件’)->where(‘a.条件=b.条件’)->order(‘a.字段 desc’)->select();
注:where(“id”,$id)也可以这样写

如果需要分页则把select()换成paginate(10,false, [ ‘query’ => request()->param(), ]);