Параметры привязки для оператора PDO внутри цикла

I ' m пытается связать параметры для SQL-запроса внутри цикла:

$db = new PDO('mysql:dbname=test;host=localhost', 'test', '');  
$stmt = $db->prepare('INSERT INTO entries VALUES (NULL, ?, ?, ?, NULL)');

$title = 'some titile';
$post = 'some text';
$date = '2010-whatever';  

$reindex = array(1 => $title, $post, $date); // indexed with 1 for bindParam

foreach ($reindex as $key => $value) {  
    $stmt->bindParam($key, $value);  
    echo "$key</br>$value</br>";  //will output: 1</br>some titile</br>2</br>some text</br>3</br>2010-whatever</br>
}

Приведенный выше код вставляет в базу данных все 3 поля 2010-любой .

Этот работает нормально:

$stmt->bindParam(1, $title);
$stmt->bindParam(2, $post);
$stmt->bindParam(3, $date);

Итак, мой вопрос почему код в цикле foreach не работает и вставляет неверные данные в поля?

25
задан Buddy 2 August 2012 в 15:00
поделиться