executeQuery with bind IN WHERE

I want to check if you see same problem or I am using the wrong way.

$ids = array(2,3,4);
$phql = "UPDATE table SET type = ?0 WHERE id IN (?1)";
$string  = implode(',', $ids);
$status = $this->modelsManager->executeQuery($phql, [0=>1,1=>$string]);

suppose it should SET type=1 for id 2,3,4, but I only see one row changed, is there something wrong with bind the way I use?



6.2k
edited Nov '16

I have used inWhere a lot with select, but I don't think ->inWhere would work for raw phql like above. The reason I want to use raw query is to update in bulk, instead of select, loop and save.

https://docs.phalconphp.com/en/latest/reference/phql.html

search for

inWhere

inside the page



64.1k

hmm I see. well you have to bind as much params as the array has.

so it will be like WHERE IN (?1,?2, ?3 ) for an array like [val1,val2,val3];

here are a lot of examples:

http://stackoverflow.com/questions/920353/can-i-bind-an-array-to-an-in-condition
edited Nov '16

I heared, since some recent version there is an ability to bind an array to query in an easy way with one placeholder. Does anyone heared about it? How to?

hmm I see. well you have to bind as much params as the array has.

so it will be like WHERE IN (?1,?2, ?3 ) for an array like [val1,val2,val3];

here are a lot of examples:

http://stackoverflow.com/questions/920353/can-i-bind-an-array-to-an-in-condition