ID: 47977 Updated by: sjo...@php.net Reported By: fhgvbrdyftgjhgtfr at gazeta dot pl -Status: Open +Status: Feedback Bug Type: PDO related Operating System: Unix PHP Version: 5.2.9 New Comment:
Thank you for your bug report. Although you supplied code to reproduce the problem, it is more complicated and longer than necessary. Please supply a short, complete and understandable piece of code to reproduce the problem. This is to make sure the problem is with PHP and not with the example. Previous Comments: ------------------------------------------------------------------------ [2009-05-16 01:20:50] fhgvbrdyftgjhgtfr at gazeta dot pl <?php $db = new PDO('mysql:dbname=test;host=localhost', 'root', ''); $array2 = array('gb', 'us', 'nz', 'fr', 'de'); $array3 = array('fr'=>true, 'de'=>true); $array = array_diff($array2, array_keys($array3)); reset($array); $size = count($array); $in = '?'; for($i = 1; $i < $size; ++$i) $in .= ', ?'; $stmt = $db->prepare('SELECT `name` FROM `table` WHERE `language` = ? AND `code` IN('.$in.')'); $stmt->bindValue(1, 'en', PDO::PARAM_STR); $i = 1; $element = current($array); do { $stmt->bindParam(++$i, $element, PDO::PARAM_STR); } while(($element = next($array)) !== false); $stmt->execute(); var_dump($stmt->fetchAll()); ?> ----------------- expected result: array(3) { [0]=> array(2) { ["name"]=> string(4) "test" [0]=> string(4) "test" } [1]=> array(2) { ["name"]=> string(4) "test" [0]=> string(4) "test" } [2]=> array(2) { ["name"]=> string(4) "test" [0]=> string(4) "test" } } -------------------- actual result: array(0) { } -------------------- db: CREATE TABLE IF NOT EXISTS `table` ( `name` varchar(45) NOT NULL, `language` enum('en','fr') NOT NULL, `code` char(2) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=utf8; INSERT INTO `table` (`name`, `language`, `code`) VALUES ('test', 'en', 'gb'), ('test', 'en', 'nz'), ('test', 'en', 'us'), ('test', 'en', 'cz'); ------------------------------------------------------------------------ [2009-05-08 01:00:02] php-bugs at lists dot php dot net No feedback was provided for this bug for over a week, so it is being suspended automatically. If you are able to provide the information that was originally requested, please do so and change the status of the bug back to "Open". ------------------------------------------------------------------------ [2009-04-30 10:47:04] j...@php.net Thank you for this bug report. To properly diagnose the problem, we need a short but complete example script to be able to reproduce this bug ourselves. A proper reproducing script starts with <?php and ends with ?>, is max. 10-20 lines long and does not require any external resources such as databases, etc. If the script requires a database to demonstrate the issue, please make sure it creates all necessary tables, stored procedures etc. Please avoid embedding huge scripts into the report. ------------------------------------------------------------------------ [2009-04-16 00:22:47] fhgvbrdyftgjhgtfr at gazeta dot pl Description: ------------ bindParam doesn't work with vars returned by current(), next() Reproduce code: --------------- <?php $array = array_diff($array2, array_keys($array3)); reset($array); $size = count($array); $in = '?'; for($i = 1; $i < $size; ++$i) $in .= ', ?'; $stmt = $db->prepare('SELECT `name` FROM `table` WHERE `language` = ? AND `code` IN('.$in.')'); $stmt->bindValue(1, 'en', PDO::PARAM_STR, 2); $i = 1; $element = current($array); do { $stmt->bindParam(++$i, $element, PDO::PARAM_STR, 2); } while(($element = next($array)) !== false); Expected result: ---------------- SELECT `name` FROM `table` WHERE `language` = 'en' AND `code` IN('us', 'gb', 'nz') Actual result: -------------- SELECT `name` FROM `table` WHERE `language` = 'en' AND `code` IN('0', '0', '0') When i change $stmt->bindParam(++$i, $element, PDO::PARAM_STR, 2); to $stmt->bindValue(++$i, $element, PDO::PARAM_STR, 2); i get: SELECT `name` FROM `table` WHERE `language` = 'en' AND `code` IN('us', 'gb', 'nz') ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=47977&edit=1