phpcodeigniterselectquery-builder

How to write a custom column and value in a SELECT clause using CodeIgniter's query builder


I want to get a custom column with a custom value with each row selection of table using CodeIgniter's select() method. In a normal MySql selection query, I can do that, but using query builder syntax, the custom column is unknown.

$this->db
    ->select('name,\'custom_col\'')
    ->from('my_table')
    ->get();

Solution

  • You can do like this:

    $this->db->select("'custom_col',name",FALSE)->from('my_table')->get();