Welcome Guest, Not a member yet? Register   Sign In
query with "IN" parameter
#1

Hi all,

I have a query like this:

Code:
SELECT x,y,x from TABLE WHERE x IN (?) and y=?

My first approach was just preparing the values of x as a string, considering the values are also strings, so I got something like:

Code:
$x = "'a','b','c'";
$y =3;
$sql =  'SELECT x,y,x from TABLE WHERE x IN (?) and y=?';
$result = $this->db->query($sql, array($x, $y));

That didn't work as codeigniter escapes the in string.

Then I read the manual and found In parameters should be passed as array, ok, new try:

Code:
$x =array('a','b','c');
$y =3;
$sql =  'SELECT x,y,x from TABLE WHERE x IN (?) and y=?';
$result = $this->db->query($sql, array($x, $y));

Then i got a mesage saying this query is invalid:


Code:
SELECT x,y,x from TABLE WHERE x IN (Array) and y=3

I'm user Code igniter 2.

Note: due to some restrictions in what I'm using this for, I cannot use other database features like using db->where_in() or similar, just db->query()

Thanks!
Am I doing anything wrong?
Reply


Messages In This Thread
query with "IN" parameter - by utodev - 05-23-2019, 03:16 AM
RE: query with "IN" parameter - by php_rocs - 05-23-2019, 06:55 AM
RE: query with "IN" parameter - by utodev - 05-25-2019, 06:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB