ID:               51138
 Updated by:       [email protected]
 Reported By:      fmaz008 at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         PDO related
 Operating System: n/a
 PHP Version:      5.2.12
 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Databases allow only to bind one value per placeholder. Nothing we can
change.


Previous Comments:
------------------------------------------------------------------------

[2010-02-25 03:43:13] fmaz008 at gmail dot com

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 this bug report at http://bugs.php.net/?id=51138&edit=1

Reply via email to