如何在Codeigniter中正确使用别名

如何在Codeigniter中正确使用别名,codeigniter,Codeigniter,这是我的密码: $this->db->select('course_name AS Course Name,course_desc AS Course Description,display_public AS Display Status',FALSE); $this->db->from('courses'); $this->db->where('tennant_id',$tennant_id); $this->db->order_by('cou

这是我的密码:

$this->db->select('course_name AS Course Name,course_desc AS Course Description,display_public AS Display Status',FALSE);
$this->db->from('courses');
$this->db->where('tennant_id',$tennant_id);
$this->db->order_by('course_name','ASC');
$query = $this->db->get();
我犯了一个错误:

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1

SELECT course_name AS Course Name, 
       course_desc AS Course Description, 
       display_public AS Display Status 
FROM (`courses`) WHERE `tennant_id` = 'elicuarto@apploma.com' 
ORDER    BY `course_name` ASC

Filename: C:\wamp\www\coursebooking\system\database\DB_driver.php

Line Number: 330
我犯了一个错误:

A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1
A Database Error Occurred

Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Name, course_desc AS Course Description, display_public AS Display Status FROM (' at line 1

SELECT course_name AS Course Name, 
       course_desc AS Course Description, 
       display_public AS Display Status 
FROM (`courses`) WHERE `tennant_id` = 'elicuarto@apploma.com' 
ORDER    BY `course_name` ASC

Filename: C:\wamp\www\coursebooking\system\database\DB_driver.php

Line Number: 330
试一试

正是你的别名中的空格让你烦恼

更新

我不知道你为什么要这么做,但我看不到任何东西阻止你写作

$this->db->select("course_name AS `{$variable}`", FALSE);
(为了简单起见,仅显示一个字段)

更新2

应该是标准的字符串转换,所以我不知道为什么它不适合你。。总是有分裂的字符串

$this->db->select('course_name AS `' . $variable . '`', FALSE);

还有一件事,是否可以将变量改为别名?它不起作用。它将只打印放在大括号中的变量名。是否缺少任何内容?是否使用双引号(“)作为字符串?使用单引号(”)将不允许变量替换。是的。我的操作与您完全相同,但打印的是变量名。是否尝试按照更新2拆分字符串?如果这也不起作用,我真的不知道