带有codeigniter的日期格式 [英] Date format with codeigniter

查看:120
本文介绍了带有codeigniter的日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何想法,为什么我得到一个语法错误与此?

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

UPDATE:

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




发生数据库错误



错误号码:1064



您的SQL语法有一个错误;检查手册,
对应于您的MySQL服务器版本正确的语法使用
near'FROM( news_articles )JOIN news_categories ON
news_articles .news_categorie在第2行



SELECT news_articles id news_articles article_title
news_categories code>,CONCAT(first_name,'',last_name)
AS作者,DATE_FORMAT(news_articles'.date_posted','%M %D, code>%Y')

状态 status_name FROM( news_articles )JOIN news_categories
ON news_articles news_categories_id = news_categories id JOIN $ b $ c> users 。 user_id JOIN
statuses ON news_articles status_id = statuses id



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



行号:74



解决方案

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

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

看起来不对,是吗?



因为 CI正在尝试自动保护您的列名称。因此,要解决这个问题,您需要将 FALSE 传递给 $ this-> db-> select()

这应该可以工作:

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


Any ideas onto why I'm getting a syntax error with this?

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

UPDATE:

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

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM (news_articles) JOIN news_categories ON news_articles.`news_categorie' at line 2

SELECT news_articles.id, news_articles.article_title, news_categories.category_name, CONCAT(first_name, ' ', last_name) AS author, DATE_FORMAT(news_articles'.date_posted', '%M %D, %Y'), statuses.status_name FROM (news_articles) JOIN news_categories ON news_articles.news_categories_id =news_categories.id JOIN users ON news_articles.author_id =users.user_id JOIN statuses ON news_articles.status_id =statuses.id

Filename: /home/xtremer/public_html/kowmanager/modules/news/models/news_model.php

Line Number: 74

解决方案

The problem is hidden in the error message. Take a look at your SQL query syntax:

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

That doesn't look right, does it?

Because CI is trying to auto-protect your column names. So, to fix this, you need to pass FALSE to the second parameter of $this->db->select(), which will stop CI from trying to auto-protect these names.

This should work:

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

这篇关于带有codeigniter的日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆