如何在成语SQL查询PHP中使用OR?

How to use OR in idiorm SQL query in PHP?

我正在开发一个应用程序,使用 idiorm(https://github.com/j4mie/idiorm) 从数据库中获取数据。

这是我的一段代码:

$messages = Model::factory('Messages')->where('from_user_id','1')->find_many();

我想包含一个 or 语句 where->('to_user_id','1')

如何将其作为 OR 语句放入我的 Idiorm 查询中?

我不熟悉习语,但是看看 source code 你应该可以使用 where_raw 来构建你自己的 where 子句:

    /**
     * Add a raw WHERE clause to the query. The clause should
     * contain question mark placeholders, which will be bound
     * to the parameters supplied in the second argument.
     */
    public function where_raw($clause, $parameters=array()) {
        return $this->_add_where($clause, $parameters);
    }

类似于->where_raw('from_user_id = ? OR to_user_id = ?', array(1, 1))

这看起来像手册告诉您为 OR 条件做的事情

$messages = Model::factory('Messages')
                   ->where_any_is(
                                  array(
                                         array('from_user_id' => 1),
                                         array('to_user_id' => 1)
                                       )
                                  )    
                   ->find_many();