We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

PHQL binding array with the IN operator

Hello,

I'm new to phalcon and i have been searching the forums and googling around but i have no clue if using the IN operator and binding an array can be done:

SomeModel::count(array( 'someField IN ?0', 'bind' => array('1') ));

When this code is executed (from a CLI app) i get the following message "Syntax error, unexpected EOF" and nothing on the apache error log

Am i doing something wrong or is this syntax not supported yet?



98.9k
edited Apr '14

PDO does not allow to bind an array as a bound parameter only strings, booleans, integers and null are supported: https://www.php.net/manual/en/pdo.constants.php

https://www.php.net/manual/en/pdostatement.bindvalue.php

https://www.php.net/manual/en/pdostatement.bindparam.php



7.0k
Accepted
answer
edited Apr '14

Ok, so this seems to be more of a PDO issue, Also i would like to note that if i change the someField IN ?0 for someField = ?0 I get the PDO Error, but with IN only the Syntax error, unexpected EOF.

And thanks for the quick answer.

workaround: https://stackoverflow.com/questions/8991688/pdo-in-array-statement-and-a-placeholder

$phql = "SELECT * FROM Some\Robots WHERE id IN ({PARAM0:array})"; $robots = $modelsManager->executeQuery($phql, [ 'PARAM0' => [1, 2, 3] ]);

Update: it's supported in Phalcon 2.0.4: https://blog.phalcon.io/post/phalcon-2-0-4-released