Skip to content
左文建 edited this page Sep 5, 2016 · 2 revisions

where条件解析

1.支持对象传入自动解析方式,使用方法如下
    /**
    * arrIns 自动将$couponQueryDTO映射到couponDTO,根据表达式映射成sql语句
    * 解析后的sql语句为 select * from coupon where id=xxx
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = $queryArr['id'];
    $data = dbquery::list_coupon_by_dto($queryDTO);
2.等于,大于,小于,大于等于,小于等于 表达式说明
    /**
    * 等于
    * 解析后的sql语句为 select * from coupon where id=xxx
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = 'xxx';

   $data = dbquery::list_coupon_by_dto($queryDTO);

    /**
    * 大于
    * 解析后的sql语句为 select * from coupon where id>xxx
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '>xxx';

    /**
    * 大于等于
    * 解析后的sql语句为 select * from coupon where id>=xxx
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '>=xxx';

    /**
    * 小于
    * 解析后的sql语句为 select * from coupon where id<xxx
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '<xxx';

    /**
    * 小于等于
    * 解析后的sql语句为 select * from coupon where id<=xxx
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '<=xxx';
3.区间表达式说明
    /**
    * 开区间
    * 解析后的sql语句为 select * from coupon where id>xxxA and id <xxxB
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '(xxxA,xxxB)';
    $data = dbquery::list_coupon_by_dto($queryDTO);

    /**
    * 闭区间
    * 解析后的sql语句为 select * from coupon where id>=xxxA and id <=xxxB
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '[xxxA,xxxB]';

    /**
    * 半开半闭区间
    * 解析后的sql语句为 select * from coupon where id>xxxA and id <=xxxB
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '(xxxA,xxxB]';

    /**
    * 半开半闭区间
    * 解析后的sql语句为 select * from coupon where id>=xxxA and id <xxxB
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '[xxxA,xxxB)';
4.in 和notin查询
    /**
    * in 查询
    * 解析后的sql语句为 select * from coupon where id in(xxxA,xxxB)
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '{xxxA,xxxB}';
    $data = dbquery::list_coupon_by_dto($queryDTO);


    /**
    * not in 查询
    * 解析后的sql语句为 select * from coupon where id not in (xxxA,xxxB)
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '!{xxxA,xxxB}';
5.like 和 not like 查询
    /**
    * like 查询
    * 解析后的sql语句为 select * from coupon where name like '%xxx%'
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = 'like(xxx)';
    $data = dbquery::list_coupon_by_dto($queryDTO);


    /**
    * notlike 查询
    * 解析后的sql语句为 select * from coupon where name not like '%xxx%'
    */
    $queryDTO     = new CouponDTO;
    $queryDTO->id = '!like(xxx)';
    $data = dbquery::list_coupon_by_dto($queryDTO);