From: andrea dot spacca at gmail dot com Operating system: Linux PHP version: 5.2.3 PHP Bug Type: PDO related Bug description: no binding with prepare/execute
Description: ------------ Binding params to placeholders in prepared query don't work (i tested the script both cli and in apache enviroment) [pdo_mysql] PDO Driver for MySQL, client library version => 5.0.34 [pdo_sqlite] PDO Driver for SQLite 3.x => enabled PECL Module version => 1.0.1 SQLite Library => 3.3.17 Reproduce code: --------------- try { $sql = 'SELECT field FROM table WHERE field = :placeholder LIMIT 0, 1'; $db = new PDO([...]); $tmp = $db->prepare($sql); $tmp->execute(array(':placeholder' => 1)); var_dump($tmp->queryString); var_dump($tmp->fetchAll()); $db = NULL; } catch (Exception $e) { var_dump($e); } Expected result: ---------------- $tmp->queryString should contain the :placeholder binded to the value passed in execute(), and (as far as the query will produce row result from the db) $tmp->fetchAll() should contain the resulted row expected output: string(61) "SELECT field FROM table WHERE field = 1 LIMIT 0, 1" array(1) { [0]=> array(2) { ["field"]=> string(1) "1" [0]=> string(1) "1" ["urlString"]=> string(44) "http://comequandofuoripiove.leonardo.it/foto" [1]=> string(44) "http://comequandofuoripiove.leonardo.it/foto" ["scheme"]=> string(4) "http" [2]=> string(4) "http" ["dominio"]=> string(32) "comequandofuoripiove.leonardo.it" [3]=> string(32) "comequandofuoripiove.leonardo.it" ["insertTimestamp"]=> string(13) "1177596562453" [4]=> string(13) "1177596562453" ["diffChk"]=> string(1) "1" [5]=> string(1) "1" } } Actual result: -------------- $tmp->quetryString haven't the :placeholder binded to the value passed in execute(), so the query won't be a valid one and $tmp->fetchAll() will be empty the same happens using PDOStatement::bindValue() or PDOStatement::bindParam() the result seems not being related to a specific db driver (i tested with mysql and sqlite) no exception is raised script output: string(61) "SELECT * FROM table WHERE field = :placeholder" array(0) { } ps: if i remove the placeholder from prepare() and then try to still bind a value in execute() an exception is raised: "SQLSTATE[HY000]: General error: 25 bind or column index out of range" -- Edit bug report at http://bugs.php.net/?id=41622&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=41622&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=41622&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=41622&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=41622&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=41622&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=41622&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=41622&r=needscript Try newer version: http://bugs.php.net/fix.php?id=41622&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=41622&r=support Expected behavior: http://bugs.php.net/fix.php?id=41622&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=41622&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=41622&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=41622&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=41622&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=41622&r=dst IIS Stability: http://bugs.php.net/fix.php?id=41622&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=41622&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=41622&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=41622&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=41622&r=mysqlcfg