【发布时间】:2013-08-13 11:27:36
【问题描述】:
这是我在 CodeIgniter 中的活动记录代码:
$this->db->...
$this->db->join('post_likes', 'post_likes.user_id="'.$this->db->escape($online_user).'" AND post_likes.post_id=post.id', 'left');
这就是它的解释方式:
LEFT JOIN `post_likes` ON `post_likes`.`user_id`="`3"` AND post_likes.post_id=post.id
它给出了错误:
`user_id`="`3"`
如何在活动记录中写入直号?
更新:
删除escape
要在您的计算机上测试它,您不需要数据库。只是尝试此代码显示错误:
$this->db->select('*')
->from('mytable')
->join('post_likes', 'post_likes.user_id="3" AND post_likes.post_id=post.id', 'left');
$query=$this->db->get('');
var_dump($this->db->last_query());
exit(0);
结果:
A Database Error Occurred
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 '` AND post_likes.post_id=post.id' at line 3
SELECT * FROM (`mytable`) LEFT JOIN `post_likes` ON `post_likes`.`user_id`="`3"` AND post_likes.post_id=post.id
【问题讨论】:
标签: codeigniter activerecord codeigniter-2