From: fmaz008 at gmail dot com
Operating system: n/a
PHP version: 5.2.12
PHP Bug Type: PDO related
Bug description: Impossible to use "IN()"
Description:
------------
Using MySQL and InnoDB table, if you prepare this query:
SELECT * FROM foo WHERE id IN(:values);
You will be totally unable to use it, thoses solutions doesn't work:
$arr = array(1,2,3,4,5);
$prep->bindParam(':values', $arr, PDO::PARAM_STMT); //Invalid Array to
String conversion
or:
$arr = array(1,2,3,4,5);
$prep->bindParam(':values', implode(',', $arr), PDO::PARAM_STR); //Seems
to be interpreted as "1,2,3,4,5" instead of "1","2","3","4","5" or plain
integer values.
============
Actual work arround is to generate a string to inject in the query string
before preparing it. But it's not a good solution as I often need to use
prepared statement in loop. So if I must prepare and reprepare and
re-reprepare, that's not usefull.
============
A PDO::PARAM_RAWSTR or PDO::PARAM_UNPROTECTED_STR might be a quick & good
workarround to solve this problem until a better fix.
Reproduce code:
---------------
$arr = array(1,2,3,4,5);
$prep->prepare('SELECT * FROM foo WHERE id IN(:values);');
$prep->bindParam(':values', implode(',', $arr), PDO::PARAM_STMT);
$prep->execute();
Expected result:
----------------
SELECT * FROM foo WHERE id IN(1,2,3,4,5);
Actual result:
--------------
SELECT * FROM foo WHERE id IN("1,2,3,4,5");
--
Edit bug report at http://bugs.php.net/?id=51138&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=51138&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=51138&r=trysnapshot53
Try a snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=51138&r=trysnapshot60
Fixed in SVN:
http://bugs.php.net/fix.php?id=51138&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=51138&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=51138&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=51138&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=51138&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=51138&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=51138&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=51138&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=51138&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=51138&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=51138&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51138&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=51138&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=51138&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=51138&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=51138&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=51138&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=51138&r=mysqlcfg