我收到这个错误:
Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /FondManager.class.php on line 69
尝试执行时:
$Fond_Modif = $Manager->get($id);
$Fond_Modif->setContactname($_POST['name']);
$Manager->update($Fond_Modif);
这是相关的类:
public function update(Fond $Fond)
{
$q = $this->_db->prepare('UPDATE fonds SET Name, ContactName, ContactPosition, ContactMail, ContactPhone, Website, MinTic, MaxTic WHERE id = :id');
$q->bindValue(':id', $Fond->id());
$q->bindValue(':name', $Fond->name(), PDO::PARAM_INT);
$q->bindValue(':contactname', $Fond->contactname(), PDO::PARAM_INT);
$q->bindValue(':contactposition', $Fond->contactposition(), PDO::PARAM_INT);
$q->bindValue(':contactmail', $Fond->contactmail(), PDO::PARAM_INT);
$q->bindValue(':contactphone', $Fond->contactphone(), PDO::PARAM_INT);
$q->bindValue(':website', $Fond->website(), PDO::PARAM_INT);
$q->bindValue(':mintic', $Fond->mintic(), PDO::PARAM_INT);
$q->bindValue(':maxtic', $Fond->maxtic(), PDO::PARAM_INT);
$q->execute();
}
最佳答案
您必须在查询中“提及”所有占位符
$q = $this->_db->prepare("UPDATE fonds
SET Name = :name,
ContactName = :contactname,
ContactPosition = :contactposition,
ContactMail = :contactmail,
ContactPhone = :contactphone,
Website = :website
MinTic = :mintic,
MaxTic = :maxtic
WHERE id = :id");
PDO 仅替换占位符。您必须将该占位符添加到您的查询中。
关于php - MysQl 错误 : Invalid parameter number,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13632116/