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]); }