【问题标题】:MySql functions with kohana ORMMySql 函数与 kohana ORM
【发布时间】:2012-04-30 07:54:14
【问题描述】:

我有点困惑如何转换我的查询:

> 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]:未知列“日期(日期创建)”在 '在哪里......

【问题讨论】:

    标签: mysql kohana kohana-3 kohana-orm


    【解决方案1】:

    'Date(date_created)' 字符串将被转义并被视为列名,除非您首先将其传递给DB::expr()。因此,请尝试以下操作,而不是 'Date(date_created)'

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

    the documentation on DB::expr()

    【讨论】:

      猜你喜欢
      • 2010-09-16
      • 2010-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-11
      • 2011-10-23
      相关资源
      最近更新 更多