Rumah > Soal Jawab > teks badan
P粉2162035452023-09-02 09:56:29
Cuba kod seperti ini:
public function mergeIDs($newID,$changeTheseIDs){ //(分别为整数和整数数组) $mergeSet = array_merge([$newID],$changeTheseIDs); $marks = array_fill(0, count($changeTheseIDs), '?'); $query = $this->connect()->prepare("UPDATE `log` SET `id` = ? WHERE `id` IN (". implode(',', $marks) .");"); $query->execute($mergeSet); }
P粉4468003292023-09-02 00:11:20
Anda memerlukan satu ?
untuk setiap integer dalam klausa IN, bukan hanya satu.
public function mergeIDs($newID,$changeTheseIDs){ //(分别是整数和整数数组) $inPH = implode(',', array_fill(0, count($changeTheseIDs), '?')); $query = $this->connect()->prepare("UPDATE `log` SET `id` = ? WHERE `id` IN ( {$inPH} );"); $query->execute([$newID, ...$changeTheseIDs]); }