SELECT string AS column

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

SELECT 'page' AS result_type,...

However, I need to create this query using active record in the codeigniter framework.

I tried this:

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

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

I've tried various other similar approaches but they all fail.

Is this even possible in Active record and if so, can you please point me in the right direction??


Are you sure your table column name is 'page'? Why is it named so? page is not a MySQL reserved word (as per v.5.5.16 - the current one) as far as I know.

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 properly use Alias in Codeigniter


因为你使用引号而不是反引号,quote(')表示它是字符串,所以试试这个

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

You can try like this

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

or this

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

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

链接地址: http://www.djcxy.com/p/43778.html

上一篇: 如何正确处理IHttpModule?

下一篇: SELECT字符串AS列