Correction status:qualified
Teacher's comments:
面向对象的更新数据
require 'mysqli_connect.php'; $sql = "UPDATE staff SET name=?,salary=? WHERE staff_id=?"; $stmt = $mysqli->stmt_init(); if ($stmt->prepare($sql)){ $stmt->bind_param('sii', $name, $salary,$staff_id); $name='yangguo';$salary=4444;$staff_id=14; $stmt->execute(); if ($stmt->affected_rows){ echo '更新成功,受影响记录'.$stmt->affected_rows; }else{ echo '更新失败'; } }else{ exit($mysqli->errno . ':' . $mysqli->error); } $mysqli->close();
PDO删除数据操作
$pdo = new PDO('mysql:dbname=php', 'root', 'root'); $sql = "DELETE FROM user WHERE user_id=:user_id"; $stmt = $pdo->prepare($sql); $stmt->bindValue(':user_id',4); $stmt->execute();
总结: 学习的面向对象的更新操作,更进步掌握了面向对象的过程
一定要加深记忆,面向对象的书写步骤
PDO 处理更简单,绑定参数可以使用bindValue或bindParam