I follow the solution from this example: PDO Prepared Inserts multiple rows in single query , i dont have any error but insert doesnt work. This is the code:
$pdo = new PDO('mysql:host=localhost;dbname=dbname;charset=utf8', 'username', 'password');
$fields = array('field1', 'field2', 'field3', 'field4');
$pdo->beginTransaction();
$insert_values = array();
foreach ($dataForInsert as $key => $value) {
$question_marks[] = '(' . $this->placeholders('?', sizeof($value)) . ')';
$insert_values = array_merge($insert_values, array_values($value));
}
$sql = "INSERT INTO table (" . implode(",", $fields ) . ") VALUES " . implode(',', $question_marks);
$stmt = $pdo->prepare($sql);
try {
$stmt->execute($insert_values);
} catch (PDOException $e){
echo $e->getMessage();
}
where i am making mistake?