这是了解PDO的非常好的教程
正确的方法是:
// Named Placeholders
$sSql = "UPDATE mytable SET FName = :FName, LName = :LName, Age = :Age, Gender = :Gender WHERE ID = :ID;";
// PDO prepared statement
$oSth = $oDbh->prepare($sSql);
// Bind Named Placeholders
$oSth->bindParam(":FName", $FName, PDO::PARAM_STR);
$oSth->bindParam(":LName", $LName, PDO::PARAM_STR);
$oSth->bindParam(":Age", $Age, PDO::PARAM_INT);
$oSth->bindParam(":Gender", $Gender, PDO::PARAM_STR);
$oSth->bindParam(":ID", $ID, PDO::PARAM_INT);
// Execute PDO with condition
if ($oSth->execute()) {
// Get Affected row
$iAffectedRows = $oSth->rowCount();
$oSth->closeCursor();
return $iAffectedRows;
} else {
// PDO error, could also be caught in a try/catch statement
$errorMsg = $oSth->errorInfo();
error_log(json_encode($errorMsg));
}