更新数据库时PHP mysql错误

标签 php mysql sql syntax pdo

我收到以下错误

Warning: PDOStatement::execute(): SQLSTATE[HY093]: 
Invalid parameter number: number of bound variables does not match number of tokens

当我尝试更新 MySQL 数据库时。

这是我使用的代码。

public function update() {
    global $db;
    $stmt = $db->prepare("UPDATE products SET Name='?', Cate_id='?', Price='?', Image='?', Special='?', Special_price='?', Disable='?' WHERE PID = ?;");
    $stmt->execute(array($this->name, $this->category, $this->price, $this->image, $this->special, $this->special_price, $this->disable, $this->id));
}

最佳答案

SET Name='?', Cate_id='?', Price='?', Image='?'  etc

在 ?

中不需要引号

应该是

SET Name=?, Cate_id=?, Price=?, Image=? etc...

关于更新数据库时PHP mysql错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22375834/

相关文章:

php - Opencart 3.x 如何在菜单中手动添加第 4 级类别项目

php - 为什么我的数组在 PHP 包含文件中不可见?

mysql - 计算 MySQL 中列的简单中位数

php - mysqli 对 foreach 执行多个查询

java - Hibernate (HQL) 查找参数列表中缺失的 id

php - 删除数组中的第一级标识符

php - MAMP-mysqli_query(): (HY000/6): Error on delete of …

mysql - 如何将单个 MSSQL 表导出到 MySQL?

php - 错误: could not find driver - Using PDO with MS Access database

SQL Join 问题...它叫什么?