CodeIgniter - implode / query绑定导致不需要的字符串 [英] CodeIgniter - implode/query binding causing unwanted string

查看:162
本文介绍了CodeIgniter - implode / query绑定导致不需要的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询尝试更新CodeIgniter:

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)));

implode正在创建一个数组中所有ID的字符串。然而,这导致查询如下:

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');

当我需要的是:

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

只有区别,是ID字符串周围的单引号。这是我需要做的自己,跳过CI的查询绑定(http://codeigniter.com/user_guide/database/queries.html)或CI是可以处理,我只是错过一步?

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?

谢谢。

推荐答案

我不认为你可以跳过这种行为。你在技术上传递一个字符串,所以CI解释它这样,并简单地用引号包围它。

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.

我认为你最好只是连接<$ c $ (例如使用 foreach 循环)转换它们,用 $ this-> db- > escape(),以防万一你确定。

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.

这篇关于CodeIgniter - implode / query绑定导致不需要的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆