變數引入方法
$sql = "UPDATE users SET name=?, surname=?, sex=? WHERE id=?";
$stmt= $pdo->prepare($sql);
$stmt->execute([$name, $surname, $sex, $id]);
OR==========================
$sql = "UPDATE users SET name=?, surname=?, sex=? WHERE id=?";
$pdo->prepare($sql)->execute([$name, $surname, $sex, $id]);
陣列方式
$data = [
'name' => $name,
'sname' => $sname,
'sex' => $sex,
'id' => $id,
];
$sql = "UPDATE users SET name=:name, sname=:sname, sex=:sex WHERE id=:id";
$stmt= $pdo->prepare($sql);
$stmt->execute($data);
OR==========================
$sql = "UPDATE users SET name=:name, sname=:sname, sex=:sex WHERE id=:id";
$pdo->prepare($sql)->execute($data)