I want to update multiple rows using pdo and update. For some reason it works for a single line update (inserted and overgiven from a html textarea) but not for multiple rows, so I think my bad is somewhere in the foreach loop which should update row by row.
Overgiven from HTML textarea (changeAccountData):
user|pass|region
user1|pass1|region1
My Php part
$accounts = explode(PHP_EOL, $_POST['changeAccountData']);
$quantity = sizeof($accounts);
// Batch size, calc iterations
$batchSize = 500;
for($idx=0;$idx*$batchSize < $quantity; $idx++){
$accountsPartial = array_slice($accounts, $idx*$batchSize, $batchSize);
// Prepare the Query
$query = "UPDATE EasyService SET password=? WHERE username=? AND region=?";
// Create the multiple value placeholder
$stmt = $db->prepare($query);
$i = 1;
foreach($accountsPartial as $item){
list($user, $pass, $region) = explode("|", $item);
$stmt->bindValue($i++, trim($pass));
$stmt->bindValue($i++, trim($user));
$stmt->bindValue($i++, trim(strtoupper($region)));
$stmt->execute();
}
}
I wonder whether I need to use bindValue or bindParam in such cases ? Why does this work for a single account but not for multiple accounts. I echoed all $user, $pass and $region already which was fine.