执行时在SQL上添加不必要的引号-Codeigniter [英] Unnecessary quotes adding on sql while executing - codeigniter

查看:251
本文介绍了执行时在SQL上添加不必要的引号-Codeigniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试执行选择查询时,我遇到了这样一种情况,即在执行时给它注入了不必要的引号。我在Codeigniter工作。试图选择前四个字符相同的记录。
代码为:

while trying to do a select query I came into a situation where unnecessary quotes are injecting to it on execution. I'm working in Codeigniter. Trying to selects record which having first 4 characters same. Code is:

$calendar = $this->db->select("c.first_name as cfn, u.first_name as ufn", false)
        ->from("{$this->tables['contacts']} c")
        ->join("{$this->tables['users']} u", " SUBSTR( u.first_name , 1 , 4) = SUBSTR( c.first_name , 1 , 4) ", '')
        ->where(array('c.status' => 1, 'c.first_name !=' => ''))
        ->get()->result_array();

我遇到以下错误:

FUNCTION dbname.SUBSTR does not exist. Check the 'Function Name Parsing 
and Resolution' section in the Reference Manual

SELECT c.first_name as cfn, u.first_name as ufn FROM (`contacts` c) 
JOIN `users` u ON `SUBSTR`( `u`.`first_name` , 1 , 4) = SUBSTR( c.first_name , 1 , 4) 
 WHERE `c`.`status` = 1 AND `c`.`first_name` != ''

`SUBSTR` 是令人兴奋(SUBSTR单引号)。

`SUBSTR` on query is unexciting(single quote for SUBSTR).

推荐答案

对于我来说,我必须通过以下方法解决此问题:

In my case, I has to fix this issue by doing:

$calendar = $this->db->query("SELECT c.first_name as cfn, u.first_name as ufn 
FROM (`contacts` c) JOIN `users` u ON 
((SUBSTR(`u`.`first_name`, 1, 4)) = (SUBSTR(`c`.`first_name`, 1, 4))) 
WHERE `c`.`status` = 1 AND `c`.`first_name` != ''")->result_array();
print_r($calendar);

这篇关于执行时在SQL上添加不必要的引号-Codeigniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆