codeigniter join query wrapping number
This is my active record code in 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');
And this is how it is interpreted:
LEFT JOIN `post_likes` ON `post_likes`.`user_id`="`3"` AND
post_likes.post_id=post.id
it gives the error:
`user_id`="`3"`
How to write a direct number in active record?
Update:
removing escape:
$this->db->join('post_likes', 'post_likes.user_id="3" AND
post_likes.post_id=post.id', 'left');
gives:
LEFT JOIN `post_likes` ON `post_likes`.`user_id`="`3"` AND
post_likes.post_id=post.id
to test it on your computer you dont need to have a database. Just trying
this code shows the error:
$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);
No comments:
Post a Comment