【发布时间】:2013-08-21 19:07:19
【问题描述】:
我正在尝试仅使用 PDO 编写更新查询我无法让我的代码执行?
try {
$conn = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
$conn->exec("SET CHARACTER SET utf8"); // Sets encoding UTF-8
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "UPDATE `access_users`
(`contact_first_name`,`contact_surname`,`contact_email`,`telephone`)
VALUES (:firstname, :surname, :telephone, :email);
";
$statement = $conn->prepare($sql);
$statement->bindValue(":firstname", $firstname);
$statement->bindValue(":surname", $surname);
$statement->bindValue(":telephone", $telephone);
$statement->bindValue(":email", $email);
$count = $statement->execute();
$conn = null; // Disconnect
}
catch(PDOException $e) {
echo $e->getMessage();
}
【问题讨论】:
-
查询错误。您正在使用类似 INSERT 的语法。在此处查看更新的语法:dev.mysql.com/doc/refman/5.0/en/update.html