I've got an array called $changedcompanies
and I want to insert the contents into my mySQL table.
Currently I'm using a for loop in php which must be an inefficent way of going about it:
for ($x=0;$x<count($changedcompanies);$x++){
try {
$sql = "INSERT INTO ecampaign_historyamend SET historyid = '".$lastid."',
companyid = '".$changedcompanies[$x]['id']."',
newcontactid = '".$changedcompanies[$x]['contactid']."'";
$s = $pdo->prepare($sql);
$s->execute();
}
catch (PDOException $e) {
$error = 'Error inserting history amend: ' . $e->getMessage();
showerror($error);
exit();
}
}
Is there a way to design a mySQL query that will insert the whole array in one go?