Edit report at http://bugs.php.net/bug.php?id=51138&edit=1

 ID:               51138
 Comment by:       greg dot martyn at gmail dot com
 Reported by:      fmaz008 at gmail dot com
 Summary:          Impossible to use "IN()"
 Status:           Bogus
 Type:             Bug
 Package:          PDO related
 Operating System: n/a
 PHP Version:      5.2.12

 New Comment:

This is a duplicate of Request #48431   Support PDO::PARAM_STMT


Previous Comments:
------------------------------------------------------------------------
[2010-02-25 11:50:30] fmaz008 at gmail dot com

This is still a major design flaw, and I'm far from beeing the only one
to ran into this problem (google a bit, you'll see)

Something should(must) be emulated.



I've also read the how to repport a bug, I can't figure out what you're
trying to tell me. And giving me a link to all the PHP manual is a bit
ridiculous.

------------------------------------------------------------------------
[2010-02-25 07:41:27] [email protected]

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.

------------------------------------------------------------------------
[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/bug.php?id=51138&edit=1

Reply via email to