ThinkPHP的where数组来实现OR查询

阅读 56

2023-08-12


你可以使用ThinkPHP的where数组来实现OR查询。在where数组中,你可以使用闭包函数来构建OR条件。以下是一个示例代码:

$where['status'] = 1;
$where['title'] = 'Hello';
$where['_logic'] = 'or';

$data = Db::name('table_name')
    ->where(function ($query) use ($where) {
        $query->where($where);
    })

    ->select();
在上面的示例中,$where数组定义了OR条件,其中status等于1或title等于'Hello'。_logic键用于指定逻辑关系为OR。在where方法中,我们使用了一个闭包函数来构建OR查询。

请注意,table_name应该替换为你的实际表名。你可以根据需要添加其他条件或字段。

精彩评论(0)

0 0 举报