【问题标题】:Date format with codeigniter使用 codeigniter 的日期格式
【发布时间】:2012-06-19 22:23:18
【问题描述】:

关于为什么我会收到语法错误的任何想法?

$this->db->select("DATE_FORMAT(".$this->news_articles_table."'.date_posted', '%M %D, %Y'");

更新:

$this->db->select("DATE_FORMAT(".$this->news_articles_table."'.date_posted', '%M %D, %Y')");

发生数据库错误

错误号:1064

您的 SQL 语法有错误;检查手册 对应于您的 MySQL 服务器版本,以便使用正确的语法 靠近'FROM (news_articles) 加入news_categories ON news_articles.`news_categorie' 在第 2 行

选择news_articles.id, news_articles.article_title, news_categories.category_name, CONCAT(first_name, ' ', last_name) 作为作者,DATE_FORMAT(news_articles'.date_posted', '%M %D, %Y'), statuses.status_name 来自 (news_articles) 加入 news_categoriesnews_articles.news_categories_id =news_categories.id加入 users 开启 news_articles.author_id =users.user_id 加入 statuses 开启 news_articles.status_id =statuses.id

文件名: /home/xtremer/public_html/kowmanager/modules/news/models/news_model.php

行号:74

【问题讨论】:

  • 该行某处的语法错误。
  • 我 100% 确定这不是错误消息所说的内容。
  • 你发布了一件事“语法错误”结果是另一件事“数据库错误”你为什么要打扰?

标签: php codeigniter


【解决方案1】:

问题隐藏在错误消息中。看看你的 SQL 查询语法:

DATE_FORMAT(news_articles'.date_posted', `'%M` %D, `%Y')`

看起来不太对,是吗?

因为CI is trying to auto-protect your column names。因此,要解决此问题,您需要将 FALSE 传递给 $this->db->select() 的第二个参数,这将阻止 CI 尝试自动保护这些名称。

这应该可行:

$this->db->select("DATE_FORMAT(".$this->news_articles_table.".date_posted, '%M %D, %Y')", FALSE);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-11
    • 2018-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-13
    相关资源
    最近更新 更多