Edit report at http://bugs.php.net/bug.php?id=40048&edit=1
ID: 40048 Comment by: ggrraay at gmail dot com Reported by: bugs dot php dot net at andrewprendergast dot com Summary: SQL IN (...) and = ANY (...) not supported by PDO Status: Bogus Type: Bug Package: PDO related Operating System: Linux Red Hat EL PHP Version: 5.2.1RC2 Block user comment: N Private report: N New Comment: >PDO does not implement query parsing it is entirely up to the database. Query parsing not needed, it can be done this way $stmt = $dbh->prepare("SELECT * FROM table WHERE id IN(:ids)"); $sth->bindValue(':ids', array(1,2,3), PDO::PARAM_ARRAY); If specified PDO::PARAM_ARRAY in bindValue method query can be parsed as this SELECT * FROM table WHERE id IN(1,2,3) not as SELECT * FROM table WHERE id IN('1,2,3') >The solution is to re-write queries to use IN (?, ?, �) It will not work if parameters array has variable length Previous Comments: ------------------------------------------------------------------------ [2007-01-08 00:23:49] bugs dot php dot net at andrewprendergast dot com Just to re-iterate some comments made about this on IRC: <ilia> again PDO is not design to "modify" or extend SQL query language <Pierre> about definition, PDO is "only" a wrapper not an abstraction layer, it does not abstract anything (besides Specifically PDO does not do any parsing of SQL queries, it just passes them directly to the database engine in question so PDO is unable to re-write the SQL to support this feature. The solution is to re-write queries to use IN (?, ?, ) ------------------------------------------------------------------------ [2007-01-07 23:46:51] nlop...@php.net I also came across this problem last week: it would be could if we could bind an array to IN(). Probably it would be too dificult, but we could support this syntax in our sql re2c lexer.. ------------------------------------------------------------------------ [2007-01-07 17:44:11] il...@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Due to the volume of reports we can not explain in detail here why your report is not a bug. The support channels will be able to provide an explanation for you. Thank you for your interest in PHP. PDO does not implement query parsing it is entirely up to the database. So the features you are talking about would only work if supported by the underlying database. ------------------------------------------------------------------------ [2007-01-07 13:35:55] bugs dot php dot net at andrewprendergast dot com Description: ------------ PDO doesn't allow one to SELECT or DELETE groups of records based on their primary key. Specifically, the SQL clauses WHERE ... IN (...) and WHERE ... = ANY (...) does not work for more than one record. As a workaround I can construct an SQL query and execute it myself but that defeats the niceness of PDO. Reproduce code: --------------- the following should return the records with ID 1 & 2: $dbh = new PDO('mysql:host=localhost;dbname=mobop', "root", ""); $stmt = $dbh->prepare("SELECT * FROM news_item WHERE news_item_id IN(?)"); if ( $stmt->execute(array("1, 2")) ) while ( ($row = $stmt->fetch()) ) print_r($row); But it doesn't. The following execute statement fails as well: $stmt->execute(array(array(2,1))) NB: The intention of the 2nd example is that when binding an array, it seems natural that PDO would assume its part of an IN or =ANY clause and convert it into a bunch of comma separated keys automagically. Some of the higher level PDO based O/R abstractions currently bouncing around like Doctrine would then be able to support (without any modificaiton) queries that affect multiple records. Expected result: ---------------- Two records should be loaded. Actual result: -------------- One record is loaded. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=40048&edit=1