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

 

tp5 model controlle sql的更多相关文章

  1. django 有model生成SQL以及现有反向表生成model

    已有models生成SQL语句 语法 python manage.py sqlall app_name   # app_name, 在settings已经导入, 如: INSTALLED_APPS = ...

  2. Mysql –>EF edmx(model first)–> Sql server table

    一.mysql environment When we create an new database,first We need draw er diagram for somebody to sho ...

  3. tp5 model 中的查询范围(scope)

    查询范围scope在model中定义,在controller中使用 namespace app\index\model; use think\Model; class User extends Mod ...

  4. tp5 model 的数据自动完成

    auto属性自动完成包含新增和更新操作 namespace app\index\model; use think\Model; class User extends Model { protected ...

  5. tp5 model 中的类型转换

    类型转换使用 $type 定义 // 保存到数据库的数据会自动转换为相对应的格式class User extends Model { protected $type = [ 'status' => ...

  6. tp5 model 中的软删除

    model中需use traits\model\SoftDelete; // 数据表中需添加一个 delete_time 字段保存删除时间 namespace app\index\model; use ...

  7. TP5 model层 返回的对象转数组

    打开 database.php 增加或修改参数'resultset_type' => '\think\Collection',即可连贯操作 model('user')->select()- ...

  8. TP5.x——打印SQL语句

    操作 使用fetchSql,然后sql就会只输出sql语句而不执行 var_dump(Db::name('user')->where(array('id'=>$this->_uid, ...

  9. tp5怎么防sql注入 xss跨站脚本攻击

    在 application/config.php 中有个配置选项 框架默认没有设置任何过滤规则,你可以是配置文件中设置全局的过滤规则 则会调用这些函数 自动过滤 // 默认全局过滤方法 用逗号分隔多个 ...

随机推荐

  1. Golang学习教程

    字节跳动已经全线从Python转Golang了,可能开始学习Golang这门语言会觉得无所适从,和Java,C++,Python等都不大一样,但是用多了会发现这门语言设计的还是很优雅的,下面总结Gol ...

  2. Java中Comparable和Comparator区别

    很好的一篇博客:http://blog.csdn.net/jq_ak47/article/details/61203817 http://www.cnblogs.com/cmxwt/p/6215253 ...

  3. 解决vscode无法安装golang相关插件的问题 - 即无法直连golang.org的问题

    喜欢挂vpn或者代理的请无视本文. 其实golang.org上的插件在github.com上都有镜像,直接 git clone https://github.com/golang/tools git ...

  4. 五、005-环境安装【docker、fabric】

    1.参考地址:https://hyperledger-fabric.readthedocs.io/en/latest/prereqs.html#install-curl 一.前置条件和系统配置 1.安 ...

  5. Rk3288 双屏异显单触摸

    系统版本:RK3288 android 5.1 设备同时有两个lcd,主屏是mipi接口,带有触摸屏,触摸屏是usb接口,副屏是hdmi接口,没有触摸屏,正常情况下,两个lcd显示相同内容,触摸屏一切 ...

  6. Web浏览器里的那些事

    初衷: 大脑中一直存在误区:一个Web前端工作者只要完美实现产品所提需求,至于浏览器究竟是怎么工作或者其中间都经历了些什么事情,就不用刨根问底了.直到最近看见前端大神winter老师关于浏览器部分的系 ...

  7. Golang 笔记 5 go语句

     Go语句和通道类型是Go语言的并发编程理念的最终体现.与defer语句相同,go语句也可以携带一个表达式语句.Go语句的执行会很快结束,并不会对当前流程的进行造成阻塞或明显的延迟.一个简单的示例: ...

  8. [LeetCode] Basic Calculator IV 基本计算器之四

    Given an expression such as expression = "e + 8 - a + 5" and an evaluation map such as {&q ...

  9. css3贝塞尔曲线

    http://yisibl.github.io/cubic-bezier/#.17,.67,.94,.53 前言 在了解 cubic-bezier 之前,你需要对 CSS3 中的动画效果有所认识,它是 ...

  10. python GIL :全局解释器

    cpython 解释器中存在一个GIL(全局解释器锁),无论多少个线程.多少颗cpu 他的作用就是保证同一时刻只有一个线程可以执行代码,因此造成了我们使用多线程的时候无法实现并行. 因为有GIL的存在 ...