如何在 Codeigniter 中正确使用别名 [英] How to properly use Alias in 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('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:wampwwwcoursebookingsystemdatabaseDB_driver.php
Line Number: 330
推荐答案
尝试
$this->db->select('course_name AS `Course Name`, course_desc AS `Course Description`, display_public AS `Display Status`', FALSE);
是你别名中的空间惹恼了你.
It's the space in your alias that is messing with you.
更新
我不知道你为什么想要,但我认为没有什么可以阻止你写作
I'm not sure why you would want to, but I see nothing preventing you from writing
$this->db->select("course_name AS `{$variable}`", FALSE);
(为简单起见仅显示一个字段)
(showing just one field for simplicity)
更新 2
应该是标准的字符串转换所以我不知道为什么它对你不起作用..总是有拆分字符串......
Should be standard string conversion so I don't know why it doesn't work for you.. there's always split strings...
$this->db->select('course_name AS `' . $variable . '`', FALSE);
这篇关于如何在 Codeigniter 中正确使用别名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文