pdo_get()、pdo_getall() – 根据条件(不等于、大于、小于、模糊)查询数据时如何传递条件

微擎开发文档中pdo_get()、pdo_getall()只说明了根据条件(AND连接)到指定的表中获取一条记录,如果是模糊、大于、小于、不等于等条件应当如何传递条件呢?

$filter = array(
    'username like' => "%mizhou%",
    'remark !=' => "",
    'starttime >=' => 1502413770,
    'starttime <=' => 1567133479,
    'status' => 1,
);
//生成的SQL等同于:SELECT username FROM ims_users WHERE username like '%mizhou%' AND status = '1' AND remark != '' AND starttime >= '1502413770' AND starttime <= '1567133479' LIMIT 1
$user = pdo_get('users', $filter, array('username'));

//$filter也可以按照下面方法书写
$filter = array(
    'username' => ' LIKE "%mizhou%" ',
    'remark' => ' != "" ',
    'starttime' => '>= 1502413770',
    'starttime' => '<=1567133479',
    'status' => 1,
);

本文来自投稿,不代表微擎百科立场,如若转载,请注明出处:https://www.w7.wiki/code/2372.html

发表评论

登录后才能评论