From:             petr at hroch dot info
Operating system: Linux Debian 4.0 Etch
PHP version:      5.3CVS-2008-03-18 (snap)
PHP Bug Type:     PDO related
Bug description:  PDO SQlite method bindParam doesn't work properly in foreach 
cycle

Description:
------------
PDO method bindParam doesn't work properly in foreach cycle

Reproduce code:
---------------
<?
  $dbh = new PDO("sqlite:test.db3");
  
  //1. CREATE TEST TABLE
  $create_table_query = "create table test (col1 varchar, col2 varchar,
col3 varchar)";
  
  if (!$sth = $dbh->prepare($create_table_query)) {
    print_r($dbh->errorInfo());  
    exit;
  }
 
  if ($sth->execute()) {
   echo "Test table created successfully\n";
  }
  $sth = null;  
 
  //2. INSERT ONE RECORD TO THE TEST TABLE
  $insert_record_query = "insert into test (col1,col2,col3) values (:col1,
:col2, :col3)"; 
  if (!$sth = $dbh->prepare($insert_record_query)) {
    print_r($dbh->errorInfo());  
    exit;
  }

  //3. DATA BINDINGS
  $bindings[":col1"] = "test value in col 1";
  $bindings[":col2"] = "test value in col 2";
  $bindings[":col3"] = "test value in col 3";
  
  foreach ($bindings as $var => $value) {
    echo "Binding data, $var => $value\n";
    $sth->bindParam($var, $value);
  }

  if ($sth->execute()) {
    echo "Record inserted successfully\n";
  }
  $sth = null;    

  //4. DISPLAY TABLE RECORD
  $show_record_query = "select * from test";
  if (!$sth = $dbh->prepare($show_record_query)) {
    print_r($dbh->errorInfo());  
    exit;
  }
 
  if ($sth->execute()) {
    print_r($sth->fetchAll(PDO::FETCH_ASSOC));    
  }

  $dbh = null;

?>

Expected result:
----------------
Test table created successfully
Binding data, :col1 => test value in col 1
Binding data, :col2 => test value in col 2
Binding data, :col3 => test value in col 3
Record inserted successfully
Array
(
    [0] => Array
        (
            [col1] => test value in col 1
            [col2] => test value in col 2
            [col3] => test value in col 3
        )

)

Actual result:
--------------
Test table created successfully
Binding data, :col1 => test value in col 1
Binding data, :col2 => test value in col 2
Binding data, :col3 => test value in col 3
Record inserted successfully
Array
(
    [0] => Array
        (
            [col1] => test value in col 3
            [col2] => test value in col 3
            [col3] => test value in col 3
        )

)

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

Reply via email to