1

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
  • Hey @Ryan can you tell me how you figured out that the variable was getting single quotes around it? Is there a php function that will output the ACTUAL query that was ran? I had a similar problem and if i would have been able to tell that single quotes were placed around my var it would have helped me tremendously. Commented Mar 3, 2011 at 23:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that's what I was thinking but wasn't sure.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.