如何在Codeigniter中正确使用Alias

Eli*_*Eli 6 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('course_name','ASC');
$query = $this->db->get();
Run Code Online (Sandbox Code Playgroud)

我收到一个错误:

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
Run Code Online (Sandbox Code Playgroud)

dan*_*eth 17

尝试

$this->db->select('course_name AS `Course Name`, course_desc AS `Course Description`, display_public AS `Display Status`', FALSE);
Run Code Online (Sandbox Code Playgroud)

你的别名中的空间正在弄乱你.

UPDATE

我不确定你为什么要这样做,但我没有看到任何阻止你写作的东西

$this->db->select("course_name AS `{$variable}`", FALSE);
Run Code Online (Sandbox Code Playgroud)

(为简单起见只显示一个字段)

更新2

应该是标准的字符串转换,所以我不知道为什么它对你不起作用..总是分裂字符串......

$this->db->select('course_name AS `' . $variable . '`', FALSE);
Run Code Online (Sandbox Code Playgroud)