문제

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