CodeIgniter - implode/query binding causing unwanted string

允我心安 提交于 2019-12-24 07:09:31

问题


I have the following query attempting an update in CodeIgniter:

$sql = "UPDATE fanout.manual_data
                SET call_leader_id = ?
                WHERE id IN (?)";

$q = $this->db->query($sql, array($leaderID, implode(", ", $empIDs)));

The implode is creating a string of all the IDs in my array. However, that is resulting in the query looking like:

UPDATE fanout.manual_data SET call_leader_id = '55993' WHERE id IN ('57232, 0097726, 0076034');

When what I need is:

UPDATE fanout.manual_data SET call_leader_id = '55993' WHERE id IN (57232, 0097726, 0076034);

Only difference, is the single quotes surrounding the string of IDs. Is this something I need to do myself and skip over CI's query bindings (http://codeigniter.com/user_guide/database/queries.html) or is something CI can handle and I'm just missing a step?

Thanks.


回答1:


I don't think you can skip that behavior. You're technically passing a string, so CI interprets it as such and simply surrounds it with quotes.

I think you're better off simply concatenating the $empIDs by hand (e.g. using a foreach loop), escaping them with $this->db->escape() in case you wanna be sure.



来源:https://stackoverflow.com/questions/4854710/codeigniter-implode-query-binding-causing-unwanted-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!