From:             jim dot gibbs at onelifemedia dot com
Operating system: Mac
PHP version:      5.4.7
Package:          PDO related
Bug Type:         Bug
Bug description:PDO: Multiple queries using multiple bindParams yields 
unexpected results

Description:
------------
Created a prepared statement, with named placeholders.  The prepared
statement 
contained 2 queries, and 3 placeholders.  2 of the placeholders were the
same, so 
they *should* become the same value.

The resulting query ended up being all three place holders being the same
value.

The results below were generated from the mysql log files.

Workaround:

Instead of using the bindParam function, I was able to send the same array
to the 
execute function, and it worked.

Test script:
---------------
$query = <<<QUERY
  DELETE FROM `authentication_hashes` WHERE session_key = :session_key;
  INSERT INTO `authentication_hashes` (`session_key`, `generated_hash`)
VALUES (:session_key, :generated_hash);
QUERY;

$dbh = new PDO('mysql:host=localhost;port=8888;dbname=foo, $user, $pass,
array (PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION));
$statement = $dbh->prepare($query);
$bind_params = array(':session_key' => $session_key, ':generated_hash' =>
$generated_hash)
foreach( $bind_params as $key => $value ){
  $statement->bindParam($key, $value);
}
$statement->execute();


Expected result:
----------------
DELETE FROM `authentication_hashes` WHERE session_key = '8675309';
INSERT INTO `authentication_hashes` (`session_key`, `generated_hash`)
VALUES 
('8675309',
'cb5606644c1d30a9d8f84cee4234a44455c82448a33f8031434ec42a6d173383')


Actual result:
--------------
DELETE FROM `authentication_hashes` WHERE session_key = 
'3966b45ae07b86de9c74163b093994fbf2a5813a06cbc9902f15e1b38a212940';
INSERT INTO `authentication_hashes` (`session_key`, `generated_hash`)
VALUES 
('3966b45ae07b86de9c74163b093994fbf2a5813a06cbc9902f15e1b38a212940', 
'3966b45ae07b86de9c74163b093994fbf2a5813a06cbc9902f15e1b38a212940')

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

Reply via email to