I´d like to add an extra column to the select for formatting purposes. The problem is that when I do

$this->db->select("NULL as ExtraColumn1")

codeigniter treats NULL as a column, so when it generates the query it's something like

SELECT `NULL` AS ExtraColumn1 ...

which of course returns a DB error. The same happens when I try

$this->db->select(" '' as ExtraColumn1")

Is there any way of doing it using activerecord?

Thanks

有帮助吗?

解决方案

Tell CodeIgniter not to wrap fields in ticks. You do this by passing false as the second parameter in select():

 $this->db->select("NULL as ExtraColumn1", false);

From the manual:

$this->db->select() accepts an optional second parameter. 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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top