|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2009-09-23 16:17 UTC] sjoerd@php.net
[2009-09-23 17:29 UTC] bjori@php.net
[2009-09-23 18:07 UTC] dhammari at q90 dot com
[2009-09-24 02:59 UTC] dbs@php.net
[2009-11-16 13:42 UTC] dbs@php.net
[2014-01-01 12:50 UTC] felipe@php.net
-Package: PDO related
+Package: PDO Core
[2015-09-26 01:33 UTC] a791446794 at 163 dot com
[2017-10-24 07:11 UTC] kalle@php.net
-Status: Assigned
+Status: Open
-Assigned To: dbs
+Assigned To:
[2017-10-24 08:29 UTC] kalle@php.net
-Package: PDO Core
+Package: PDO related
[2017-10-24 18:51 UTC] adambaratz@php.net
-Summary: PDO_Statement->bindParam binds multiple parameters of
the same name
+Summary: emulated prepared statements allow multiple
parameters of the same name
-Package: PDO related
+Package: PDO Core
[2017-10-24 18:51 UTC] adambaratz@php.net
[2017-10-24 23:49 UTC] kalle@php.net
-Package: PDO Core
+Package: PDO related
[2021-09-28 12:25 UTC] cmb@php.net
-Status: Open
+Status: Closed
-Type: Bug
+Type: Documentation Problem
-Assigned To:
+Assigned To: cmb
[2021-09-28 12:25 UTC] cmb@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 14:00:01 2025 UTC |
Description: ------------ My PDO Statement seems to bind multiple parameters of the same name even though the PDO->Prepare documentation indicates that this should fail: "You cannot use a named parameter marker of the same name twice in a prepared statement." Nevertheless, my SQL statement that is reusing the same parameter is getting through and returning a valid result set from a MySQL engine. PHP Version: 5.2.9-pl2-gentoo System: Linux 2.6.27-gentoo-r8 Reproduce code: --------------- <?php // CREATE TABLE `testError` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `Name` VARCHAR( 50 ) NOT NULL , `Description` TEXT NOT NULL); // INSERT INTO `testError` (`id` , `Name` , `Description`) VALUES ('1', 'Binds Both Parameters', 'Seems to bind both parameters'), ('2', 'Binds All Parameters', 'Seems to bind all parameters'); $pdo = new PDO($_SESSION["API_DB_dsn"], $_SESSION["API_DB_username"], $_SESSION["API_DB_password"]); $sql = "SELECT * FROM testError WHERE id >= :myParameter AND LENGTH(name) > :myParameter AND 1 = :myParameter"; $params = array("myParameter" => 1); $statement = $pdo->prepare($sql); foreach($params as $key => $value){ $statement->bindParam(":".$key, $value); } $statement->debugDumpParams(); $success = $statement->execute(); if(!$success){ echo("\n<p style='color:red;'>SQL FAILED</p>\n"); var_dump($pdo->errorInfo()); var_dump($statement->errorInfo()); } else{ echo("\n<p style='color:green;'>SQL SUCCEEDED</p>\n"); $result = $statement->fetchALL(PDO::FETCH_ASSOC); var_dump($result); } ?> Expected result: ---------------- I expect to see the following error: Invalid parameter number: number of bound variables does not match number of tokens SQL FAILED array 0 => string '00000' (length=5) array 0 => string 'HY093' (length=5) Actual result: -------------- Instead, I get the following: SQL SUCCEEDED array 0 => array 'id' => string '1' (length=1) 'Name' => string 'Binds Both Parameters' (length=21) 'Description' => string 'Seems to bind both parameters' (length=29) 1 => array 'id' => string '2' (length=1) 'Name' => string 'Binds All Parameters' (length=20) 'Description' => string 'Seems to bind all parameters' (length=28)