采用活动记录中不起作用codeIgniter在查询中DATE_FORMAT [英] DATE_FORMAT within a query in CodeIgniter using Active Record don't work
问题描述
codeRS。我在这里运行的一个小问题,无法找到解决办法。我使用的活动记录从CI构建查询。这是code的查询:
coders. I'm running a little problem here and can't find the solution. I'm building a query using Active Record from CI. This is the code for the query:
$this->db->select("u.id AS user_id, u.email, p.display_name, p.first_name, p.last_name, s.status_id, s.message");
$this->db->select("DATE_FORMAT(s.created_at, `Publicado el %d/%m/%Y a las %h:%i %p`) AS created_at", FALSE);
$this->db->join($this->_table_users . ' u', 'u.id = s.user_id');
$this->db->join($this->_table_profiles . ' p', 'p.user_id = u.id');
$this->db->where_in('user_id', $str);
$this->db->where('deleted', 0);
$this->db->from($this->_table . ' s');
$this->db->order_by('s.created_at', 'desc');
不过,我得到这个错误:
But I'm getting this error:
错误编号:1054
未知列'发表埃尔%D /%M /%Y一拉斯%H:%I%P在字段列表
Unknown column 'Publicado el %d/%m/%Y a las %h:%i %p' in 'field list'
选择 U
。 ID
AS USER_ID, U
电子邮件
, P
。 DISPLAY_NAME
, P
。 FIRST_NAME
,
P
。姓氏
,取值
。 status_id
,取值
。的消息
,DATE_FORMAT(s.created_at,发表EL>%D /%M /%Y一拉斯%H:%I%P
)AS created_at FROM( default_status
取值, default_status
)JOIN> default_users
U的ON U
。 ID
= default_s
。 USER_ID
加入 default_profiles
P号
P
。USER_ID = U
。 > ID
,其中 USER_ID
IN('5726,2,10293')和删除
= 0订购
BY 取值
。 created_at
递减限制2
SELECT u
.id
AS user_id, u
.email
, p
.display_name
, p
.first_name
,
p
.last_name
, s
.status_id
, s
.message
, DATE_FORMAT(s.created_at, Publicado el > %d/%m/%Y a las %h:%i %p
) AS created_at FROM (default_status
s, default_status
) JOIN > default_users
u ON u
.id
= default_s
.user_id
JOIN default_profiles
p ON
p
.user_id
= u
.id
WHERE user_id
IN ('5726, 2, 10293') AND deleted
= 0 ORDER
BY s
.created_at
desc LIMIT 2
有哪位知道在哪里可以此查询中使用DATE_FORMAT?有趣的是相同的查询写纯SQL工程 欢呼和预先感谢
Does any know where I can use DATE_FORMAT within this query? The funny is the same query write as pure SQL works Cheers and thanks in advance
推荐答案
添加FALSE在你的SELECT语句的第二个参数。您可能需要做同样的事情在你的WHERE子句中也是如此。
Add FALSE as the second parameter in your SELECT statement. You may have to do something similar in your WHERE clause as well.
一些链接查看:
http://ellislab.com/forums/viewthread/74206/#368778
http://ellislab.com/forums/viewthread/206962/#963061
http://ellislab.com/$c$cigniter/用户指南/助理/ date_helper.html
这篇关于采用活动记录中不起作用codeIgniter在查询中DATE_FORMAT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!