Blogger Information
Blog 14
fans 0
comment 0
visits 16098
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
链式查询操作 ->
依然很m丶的博客
Original
1421 people have browsed it

find() 查询

<?php
namespace app\index\controller;
use \think\Db;
class Index
{
    public function index()
    {
        return '正在学习中...';
    }
    public function demo()
    {
        dump(
          Db::table('shop_name')
              ->field(['id','name','type'])
              ->where('id',16)
              ->find()  //返回查询结果
        );
    }
}

数组查询方式

<?php
namespace app\index\controller;
use \think\Db;
class Index
{
    public function index()
    {
        return '正在学习中...';
    }
    public function demo()
    {
        dump(
          Db::table('shop_name')
              ->field(['id','name','type'])
              ->where([
                  'price'=>['>', 15],
                  ])
              ->select()  //返回查询结果
        );
    }
}

闭包查询

<?php
namespace app\index\controller;
use \think\Db;
class Index
{
    public function index()
    {
        return '正在学习中...';
    }
    public function demo()
    {
        dump(
          Db::table('shop_name')
              ->field(['id','name','price','type'])
              ->where(function ($query){
                  $query->where('price','>','15');
              })
              ->select()  //返回查询结果
        );
    }

简化:
<?php
namespace app\index\controller;
use \think\Db;
class Index
{
    public function index()
    {
        return '正在学习中...';
    }
    public function demo()
    {
        dump(
          Db::select(
             function ($query){
              $query->table('shop_name')
                  ->field(['name','price','type'])
                  ->where([
                      'id'=> ['=',1]
                  ]);
          }
        )
        );
    }
}
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