我使用Codeigniter和MSSQL数据库并遇到查询问题,我使用以下方式使用活动记录类
$this->db->protect_identifiers('content');
$this->db->protect_identifiers('url');
$this->db->select('url.url AS url, content.title AS title, content.id AS id');
$this->db->from('content');
$this->db->where('content.parent',$parent);
$this->db->where('content.menu',1);
$this->db->where('content.live',1);
$this->db->where('url."default"',1);
$this->db->join('url', 'content.id = url.content_id');
$this->db->order_by('content."order"','ASC');
正在构建以下查询并导致错误
SELECT url.url AS url, content.title AS title, content.id AS id FROM content JOIN url ON content.id = url.content_id WHERE content.parent = 0 AND content.menu = 1 AND content.live = 1 AND url."default" = 1 ORDER BY content."order" ASC
如果我通过SQL Studio运行相同的查询,它执行正常
任何想法都出错了?
答案 0 :(得分:0)
您有一个名为" ORDER"的字段。不要在SQL Server中为保留字命名字段。