在哪里进行这样的查询,我该怎么办?
SELECT * FROM hotels WHERE name LIKE '%mykey%' AND country_id = '12'
我已经这样做了,但我们不能:
$select = $this->sql->select();
$select->from(self::TABLE);
if ($params['key'])
{
$where['where'] = new \Zend\Db\Sql\Predicate\Like('name', '%'.$params['key'].'%');
}
if($params['country_id'])
{
$where['where'] = array(
'country_id' => $params['country_id']
);
}
$select->where($where['where']);
$select->order('id DESC');
$statement = $this->sql->prepareStatementForSqlObject($select);
return $statement->execute();
有义务使 if 语句改变查询的行为。我能怎么做?