php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51138 Impossible to use "IN()"
Submitted: 2010-02-25 03:43 UTC Modified: 2010-02-25 11:50 UTC
From: fmaz008 at gmail dot com Assigned:
Status: Not a bug Package: PDO related
PHP Version: 5.2.12 OS: n/a
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: fmaz008 at gmail dot com
New email:
PHP Version: OS:

 

 [2010-02-25 03:43 UTC] 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");

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-25 07:41 UTC] johannes@php.net
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 11:50 UTC] 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-05-17 17:53 UTC] greg dot martyn at gmail dot com
This is a duplicate of Request #48431  	Support PDO::PARAM_STMT
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC