语法错误SQL Codeigniter

时间:2015-06-16 12:56:29

标签: sql codeigniter syntax

我的代码中有这个,我使用codeigniter但它产生了错误

        // make call to db and create a file
        $this->db->select("*");
        $this->db->from("mst_global_settings mgs");
        $this->db->join("trans_global_settings tgs", "mgs.global_name_id=tgs.global_name_id", "inner");
        $this->db->where('`tgs`.lang_id', $lang_id);
        $query = $this->db->get();
        $result = $query->result_array();
        $tmp_array = array();
        foreach ($result as $global_array) {
            $tmp_array[$global_array["name"]] = $global_array["value"];
        }

Codeigniter给我以下错误

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 'tgs`.`lang_id` = 'en'' at line 4

SELECT * FROM (`p931_mst_global_settings` mgs) INNER JOIN `p931_trans_global_settings` tgs ON `mgs`.`global_name_id`=`tgs`.`global_name_id` WHERE `p931_`tgs`.`lang_id` = 'en'

Filename: /models/mdl_common.php

Line Number: 26

1 个答案:

答案 0 :(得分:2)

问题是你的单引号。

改变这个:

$this->db->where('`tgs`.lang_id', $lang_id);

对此:

$this->db->where('tgs.lang_id', $lang_id);