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.