|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-06-01 19:49 UTC] mail+php at requinix dot net
[2012-06-01 19:51 UTC] mail+php at requinix dot net
[2012-06-04 23:41 UTC] johannes@php.net
-Status: Open
+Status: Not a bug
[2012-06-04 23:41 UTC] johannes@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 10:00:01 2025 UTC |
Description: ------------ I have noticed an issue when working with MySQL and PDO prepare statements. If running a foreach on an array which contains the params for the prepare statement, all params equal the value of the last param in the array. See below. Test script: --------------- $pdo = new PDO('mysql:dbname=netsec_v2;host=localhost;', 'root', ''); $stmt = $pdo->prepare("CREATE TABLE BugTest ( ID int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ID), ColumnA varchar(15) NOT NULL, ColumnB int NOT NULL )"); $stmt->execute(); $array = array(":ColumnA" => "A", ":ColumnB" => 1); $stmt2 = $pdo->prepare("INSERT INTO BugTest (ColumnA,ColumnB) VALUES (:ColumnA, :ColumnB)"); foreach($array as $param => $value){ $stmt2->bindParam($param, $value); } $stmt2->execute(); $res = $pdo->query("SELECT * FROM BugTest")->fetchAll(PDO::FETCH_ASSOC); var_dump($res); Expected result: ---------------- ColumnA = A ColumnB = 1 Actual result: -------------- ColumnA = 1 ColumnB = 1