P粉2162035452023-09-02 09:56:29
嘗試類似這樣的程式碼:
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
你需要為IN子句中的每個整數準備一個?
,不能只有一個。
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]); }