• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
唯我不信
博客园    首页    新随笔    联系   管理    订阅  订阅

tp5 model controlle sql

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(), ]);

 

 
posted @ 2018-05-23 15:18  唯我不信  阅读(116)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3