0

在 Yii 框架中使用 BETWEEN 的正确方法是什么?

代码:

...
$criteria = new CDbCriteria;
$criteria->condition = 'datetime BETWEEN '.$datetimemin.' AND '.$datetimemax;
$user = Users::model()->find($criteria); 
...

错误:

SQL: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '07:10:10 AND 2011-10-10 13:10:10)' at line 1. 
4

2 回答 2

12

最正确的

$criteria->addBetweenCondition('attributeName', 'value1', 'value2');
于 2013-08-30T16:37:46.737 回答
2

我不知道在 Yii 中“正确”的做法。

但错误是因为需要引用日期。

$criteria->condition = 'datetime BETWEEN "'.$datetimemin.'" AND "'.$datetimemax.'"';
于 2012-11-01T00:04:05.573 回答