我对如何转换我的查询有点困惑:
> SELECT COUNT(`id`) AS `total_logs`, `userlog`.* FROM `user_log` AS
> `userlog` WHERE `user_id` = '31' AND date(`date_created`) =
> '2012-04-30'
到 Kohana 3.1 ORM?目前我正在使用:
> $isLoged = ORM::factory('Userlog')->select(array('COUNT("id")',
> 'total_logs'))
> ->where('user_id', '=', $user->id)
> ->and_where('Date(date_created)', '=', date('Y-m-d'))
> ->find_all();
不幸的是上面一个给出了错误:(
Database_Exception [ 1054 ]: Unknown column 'Date(date_created)' in 'where cla....
最佳答案
'Date(date_created)'
字符串将被转义并视为列名,除非您先将其传递给 DB::expr()
。因此,不要使用 'Date(date_created)'
尝试以下操作:
DB::expr('Date(date_created)')
关于MySql 函数与 kohana ORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10380261/