这里的代码。请帮我!!!非常感谢
警告:PDOStatement :: execute():SQLSTATE [HY093]:参数号无效:参数未定义
public function update($table, $data, $cond){
$updateKeys = NULL;
foreach ($data as $key => $value) {
$updateKeys .= "$key=:$key";
}
$updateKeys = rtrim($updateKeys, ",");
$sql = "UPDATE $table SET $updateKeys WHERE $cond";
$stmt = $this->prepare($sql);
foreach ($data as $key => $value) {
$stmt->bindParam(":$key", $value);
}
return $stmt->execute();
}
答案 0 :(得分:0)
您需要在$updateKeys .= "$key=:$key,";
中加上“,”。请使用
function update($table, $data, $cond){
$updateKeys = NULL;
foreach ($data as $key => $value) {
$updateKeys .= "$key=:$key,";
}
$updateKeys = rtrim($updateKeys, ",");
echo $sql = "UPDATE $table SET $updateKeys WHERE $cond";
$stmt = $this->prepare($sql);
foreach ($data as $key => $value) {
$stmt->bindParam(":$key", $value);
}
return $stmt->execute();
}