条件设置

通过 where($where, $whereData) 设置条件

功能 :设置sql条件(预处理机制)
参数 :1、条件(使用 ? 作为占位符)2、条件占位符对应的数值(数组格式)
返回 : 数据操作对象,可以进行连贯操作
演示 : $db->where('st_id = ? and st_name = ?', array(6, 'test'))

like 模糊查询示例

通过 like 进行模糊数据查询的例子 : 

class indexController extends grace{
    public function index(){
        $db   = \db('students');
        $res  =  $db
            ->where('st_id > ? or st_name like ? ', array(1,'%美%'))
            ->fetchAll();
        p($res);
    }
}

in 查询示例

通过 in 进行数据查询的例子 : 

class indexController extends grace{
    public function index(){
        $db   = \db('students');
        $res  =  $db
            // 此处 in 的数据可以利用 php 动态组合
            ->where('st_id in (1,2,3,4,5)', null)
            ->fetchAll();
        p($res);
    }
}

多条件及组合条件

可以利用 and 和 or 关键字配合 () 进行多条件查询,例子 : 

class indexController extends grace{
    public function index(){
        $db   = \db('students');
        $res  =  $db
            ->where('st_id in (1,2,3,4,5) and (st_id > ? or st_id < ?)', array(1, 100))
            ->fetchAll();
        p($res);
    }
}