您的位置:首页 > 编程语言 > PHP开发

thinkphp多条件查询(AND, OR)

2017-10-24 17:47 465 查看
SELECT * FROM `ecs_order_info` WHERE
( ( `order_status` = 5 AND `shipping_status` = 2 ) OR `order_status` = 6 ) AND `user_id` = 1

上面标红的where查询语句在TP中的拼接如下:

    $order=M('order_info');

    $where['order_status']=5;

    $where['shipping_status']=2;

    $map['_complex'] = $where;

    $map['order_status']=6;

    $map['_logic'] = 'or';  

    $final['_complex'] = $map;

    $final['user_id']=1;

   然后直接查询就可以了: $order->where($final)->select();

   问题来了,怎么检测我们写的sql语句没有错呢?执行下面这条语句就可以了,只会翻译成sql语句,不会执行。

   echo $order->where($final)->fetchSql(true)->select();

转自:http://blog.csdn.net/landylxy/article/details/70139841
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: