У меня есть объединенный массив со значением типа [ключ] => и я хочу вставить его в таблицу mysql, используя подготовленный оператор PDO. Мой код, как показано ниже:
$a = array('avocado', 'apple', 'banana');
$b = array('green', 'red', 'yellow');
$c = array_combine($a, $b);
print_r($c);
$stmt = $pdo->prepare("INSERT INTO fruits (name, color) VALUES (?,?)");
try {
$pdo->beginTransaction();
foreach ($c as $row)
{
$stmt->execute($row);
}
$pdo->commit();
}catch (Exception $e){
$pdo->rollback();
throw $e;
}
However, when I execute the statement, I get an error code:
Warning: PDOStatement::execute() expects parameter 1 to be array, string given in C:\xampp\htdocs\mysites\PDOmysql_tutorial\pdoInsert.php on line 19. Could I get a little help to correct my code or a comment if I am using the right approach. Thanks