因为我codeigniter返回语法错误?
$handler_feedback = $this->CI->db
->select('
feedback.id as feedback_id,
feedback.titulo,
relacion_feedback_usuario_principal.valor
')
->from('feedback')
->join(
'relacion_feedback_usuario_principal',
'
relacion_feedback_usuario_principal.feedback_id = feedback.id AND
relacion_feedback_usuario_principal.usuario_principal_id = 20
',
'left'
)
->get();
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 '' at line 3
SELECT `feedback`.`id` as feedback_id, `feedback`.`titulo`, `relacion_feedback_usuario_principal`.`valor` FROM (`feedback`) LEFT JOIN `relacion_feedback_usuario_principal` ON `relacion_feedback_usuario_principal`.`feedback_id` = `feedback`.`id` AND
Filename: /dir/file.php
Line Number: 289
小米原始查询:
SELECT
feedback.id as feedback_id,
feedback.titulo,
relacion_feedback_usuario_principal.valor
FROM feedback
LEFT JOIN relacion_feedback_usuario_principal ON (
relacion_feedback_usuario_principal.feedback_id = feedback.id AND
relacion_feedback_usuario_principal.usuario_principal_id = 20
)
最佳答案
它应该按照您编写的方式工作。
就这么简单
$this->db->join('B', 'aCol = bCol AND bOtherCol = 0');
$this->db->get('A');
无论如何,您都可以尝试其他方法(带有
join
子句的where
),$this->db->select('t1.id as feedback_id, t1.titulo, t2.valor');
$this->db->from('feedback as t1');
$this->db->join('relacion_feedback_usuario_principal as t2', 't1.id = t2.feedback_id', 'left');
$this->db->where('t2.usuario_principal_id', 20);
$query = $this->db->get();
关于php - Codeigniter SQL语法错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28834972/