Blogger Information
Blog 43
fans 0
comment 0
visits 26886
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp数据库查询方法+2018年10月24日
Lee的博客
Original
801 people have browsed it
  1. 数据库原生查询的实现方法
    2. 数据库闭包查询
    3. 练习课程中未演示的其它链式方法;


  2. 实例

    <?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);
            }
        }
    }

    运行实例 »

    点击 "运行实例" 按钮查看在线实例



QQ截图20181028175243.jpg

Correction status:Uncorrected

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post