在codeigniter中使用DATE FORMAT时,在选择查询中使用FALSE的用法是什么 [英] what is the use of putting FALSE in select query when using DATE FORMAT in codeigniter
问题描述
我想知道下面代码的原因
$ this-> db-> select(DATE_FORMAT `current_date`,'%M-%d-%Y')as date_human,FALSE);
当我使用上面的代码,它返回一个结果 July -09-2015
,现在我想知道是什么是使用 FALSE
here.Because我得到相同的结果,当不添加FALSE
我已参照[LINK](日期格式与codeigniter 点火器)。
编辑: >
当我使用 $ this-> db-> last_query
时,我得到的查询是:
SELECT *,DATE_FORMAT(current_date,'%M-%d-%Y')as date_human FROM`user_data`WHERE id ='57'
当使用FALSE和FALSE时。
差异和使用FALSE。
当您使用 $ this-> db-
时, > select()
CodeIgniter自动保护您的列名称。
如果将其设置为 FALSE
,CodeIgniter将您的字段或表名与反引号
。
这在需要复合select语句时非常有用。
示例
$ this-> db-> select('(SELECT SUM(payments.amount)FROM payments WHERE payments.invoice_id = 4')AS amount_paid'假);
$ query = $ this-> db-> get('mytable');
阅读CodeIgniter active_record.html#select
I want to know reason behind the below code
$this->db->select("DATE_FORMAT(`current_date`, '%M-%d-%Y' ) as date_human", FALSE);
When i'm using the above code, it is returning a result July-09-2015
, Now i want to know what is the use of FALSE
here.Because I'm getting the same result when not adding FALSE.
I have referred the [LINK](Date format with codeigniter igniter). In this, the expert says that it will stop CI from trying to auto-protect these names.
Edit:
When I use $this->db->last_query
, the query i'm getting is:
SELECT *, DATE_FORMAT(current_date, '%M-%d-%Y' ) as date_human FROM `user_data` WHERE id = '57'
when using both FALSE and without FALSE.
I want to know the difference and also the use of FALSE.
Guide me to proceed.
解决方案 When you use $this->db->select()
CodeIgniter auto protect your column names.
If you set it to FALSE
, CodeIgniter will not try to protect your field or table names with backticks
.
This is useful if you need a compound select statement.
Example
$this->db->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4') AS amount_paid', FALSE);
$query = $this->db->get('mytable');
Read CodeIgniter active_record.html#select
这篇关于在codeigniter中使用DATE FORMAT时,在选择查询中使用FALSE的用法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!