CodeIgniter 中使用 Active Record 的查询中的 DATE_FORMAT 不起作用

2024-04-27

编码员。我在这里遇到一个小问题,找不到解决方案。我正在使用 CI 的 Active Record 构建查询。这是查询的代码:

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

但我收到这个错误:

错误号:1054

“字段列表”中存在未知列“Publicado el %d/%m/%Y a las %h:%i %p”

SELECT u.id作为用户 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 创建于 FROM (default_status s, default_status) 加入>default_users u ON u.id = default_s.user_id JOIN default_profilesp.user_id = u.id WHERE user_id在 ('5726, 2, 10293') 和deleted= 0 订单 经过s.created_at描述限制 2

有谁知道我可以在这个查询中使用 DATE_FORMAT 吗?有趣的是,与纯 SQL 工作方式相同的查询编写 提前欢呼和感谢


添加 FALSE 作为 SELECT 语句中的第二个参数。您可能还需要在 WHERE 子句中执行类似的操作。

一些要查看的链接:

http://ellislab.com/forums/viewthread/74206/#368778 http://ellislab.com/forums/viewthread/74206/#368778

http://ellislab.com/forums/viewthread/206962/#963061 http://ellislab.com/forums/viewthread/206962/#963061

http://ellislab.com/codeigniter/user-guide/helpers/date_helper.html http://ellislab.com/codeigniter/user-guide/helpers/date_helper.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CodeIgniter 中使用 Active Record 的查询中的 DATE_FORMAT 不起作用 的相关文章