From:             mike dot mackintosh at angrystatic dot com
Operating system: Ubuntu 12.04 x86_64
PHP version:      5.4.4RC2
Package:          PDO related
Bug Type:         Bug
Bug description:foreaching bindparam results in all params equaling last value

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

-- 
Edit bug report at https://bugs.php.net/bug.php?id=62207&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62207&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62207&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62207&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62207&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62207&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62207&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62207&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62207&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62207&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62207&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62207&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62207&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62207&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62207&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62207&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62207&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62207&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62207&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62207&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62207&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62207&r=mysqlcfg

Reply via email to