简体   繁体   English

MySql与kohana ORM一起运行

[英]MySql functions with kohana ORM

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? 到Kohana 3.1 ORM? currently im 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.... Database_Exception [1054]:'where cla ...中的未知列'Date(date_created)'

'Date(date_created)' string will be escaped and treated as a column name, unless you will first pass it to DB::expr() . 'Date(date_created)'字符串将被转义并视为列名,除非您首先将其传递给DB::expr() Thus instead of 'Date(date_created)' try the following: 因此,请尝试以下方法,而不是'Date(date_created)'

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

See the documentation on DB::expr() . 请参阅有关DB::expr()的文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM