如何在PHP中的idiorm SQL查询中使用OR?

时间:2016-05-18 19:18:06

标签: php mysql idiorm

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

这是我的代码:

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

我想要包含where->('to_user_id','1')

的陈述或陈述

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

2 个答案:

答案 0 :(得分:5)

这看起来就像手册告诉你要对OR条件做的那样

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

答案 1 :(得分:2)

我不熟悉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))

这样的东西