質問

I'm bit confuse how to convert my query :

> SELECT COUNT(`id`) AS `total_logs`, `userlog`.* FROM `user_log` AS
> `userlog` WHERE `user_id` = '31' AND date(`date_created`) =
> '2012-04-30'

to Kohana 3.1 ORM? currently i m using :

> $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();

unfortunately above one is giving error :(

Database_Exception [ 1054 ]: Unknown column 'Date(date_created)' in 'where cla....

役に立ちましたか?

解決

'Date(date_created)' string will be escaped and treated as a column name, unless you will first pass it to DB::expr(). Thus instead of 'Date(date_created)' try the following:

DB::expr('Date(date_created)')

See the documentation on DB::expr().

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top