7

这是我的代码:

$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
4

1 回答 1

18

尝试

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

是您的别名中的空间惹恼了您。

更新

我不知道你为什么要这样做,但我认为没有什么能阻止你写作

$this->db->select("course_name AS `{$variable}`", FALSE);

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

更新 2

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

$this->db->select('course_name AS `' . $variable . '`', FALSE);
于 2013-01-24T11:50:33.687 回答