我在使用PDO与php进行“更新”时遇到了麻烦。
错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' on line 25
任何人都可以帮忙吗?
function update($table,$data,$id){
global $conn;
$resultstr = array();
foreach ($data as $keys => $value) {
$resultstr[] = $keys."=:".$keys;
}
$values = implode(",",$resultstr);
$sql ="Update ".$table." SET ".$values."WHERE id=:id";
$query = $conn->prepare($sql);
$query->bindParam(':id',$id);
foreach($data as $key=>$val){
$query->bindValue(':'.$key,$val);
}
$updateData = $query->execute();
return $updateData;
}