Codeigniter Active Record - SELECT column of AS row

I have the following, which works fine as a standard MySQL query:

SELECT 'page' AS result_type,...

      

However, I need to create this request using an active post within the codeigniter.

I've tried this:

$this->db->select('\'page\' AS result_type');

      

But this returns an error saying Unknown column ''page'' in 'field list'

I've tried various other similar approaches, but they all don't work.

Is this possible in an active post, and if so, can you point me in the right direction?

+3


source to share


3 answers


Are you sure the table column name is "page"? Why is it called that? As far as I know, page

it is not a MySQL reserved word (according to section 5.5.16 - current).

Try using the following syntax:



$this->db->select('\'page\' AS `result_type`,... ...');
$query = $this->db->get('your_table');

      

This post may help you: How to Use Alias ​​Correctly in Codeigniter

+1


source


because you are using quotes instead of backtick, quote (') means it is a string, so try that instead



 $this->db->select('`page` AS result_type');

      

+1


source


You can try like this

$this->db->select("'page' AS result_type",FALSE);

      

or

$this->db->select('\'page\' AS result_type',FALSE);

      

add FALSE parameter at the end of $ this-> db-> select ('\' page \ 'AS result_type' , FALSE );

0


source







All Articles