2

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

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@john Conde I use but this is still say error Unknown column '""' in 'field list'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.