1

Binding less values for a new row using prepared statement than the previous row, actually writes data from previous row.

Look at this example:

$db = new SQLite3('test.sqlite');
$db->exec('CREATE TABLE IF NOT EXISTS test (column1, column2, column3);');

$stmt  = $db->prepare('INSERT INTO test (column1, column2, column3) values (:0, :1, :2)');

$data = array(
  array('a', 'b', 'c'),
  array('a', 'b', 'c'),
  array('x')
);

foreach($data as $row)
{
  foreach($row as $index => $column)
  {
    $stmt->bindValue(':'.$index, $column, SQLITE3_TEXT);
  }
  $stmt->execute();
  $stmt->clear();
}

Expected behavior is following table:

a|b|c
a|b|c
x||

Actually the result is

a|b|c
a|b|c
x|b|c

I'd like to understand it if the behavior is on purpose. ::clear doesn't seem to clear bound values at all.

Boris
  • 360
  • 2
  • 12
  • You must call [reset](http://www.php.net/manual/en/sqlite3stmt.reset.php) after `execute`, but that shouldn't make any difference for the parameters … – CL. Mar 14 '14 at 15:52
  • Even with $stmt->reset() it's the same result. – Boris Mar 14 '14 at 16:11

0 Answers0