执行时在 sql 上添加不必要的引号 - codeigniter
Unnecessary quotes adding on sql while executing - codeigniter
在尝试执行 select 查询时,我遇到了一种情况,即在执行时向其注入了不必要的引号。我在 Codeigniter 工作。尝试 selects 记录前 4 个字符相同。
代码是:
$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 的单引号)。
我曾经遇到过同样的问题,我使用
解决了它
str_replace('"','',$string);
就我而言,我必须通过以下方式解决此问题:
$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);
在尝试执行 select 查询时,我遇到了一种情况,即在执行时向其注入了不必要的引号。我在 Codeigniter 工作。尝试 selects 记录前 4 个字符相同。 代码是:
$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 的单引号)。
我曾经遇到过同样的问题,我使用
解决了它str_replace('"','',$string);
就我而言,我必须通过以下方式解决此问题:
$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);