Correction status:qualified
Teacher's comments:
mysqli面向对象更新操作,PDO删除
mysqli_update.php
<?php $dbhost='localhost'; $dbuser='root'; $dbpassword='root'; $dbname='user'; $db=new mysqli($dbhost,$dbuser,$dbpassword,$dbname); if ($db->connect_errno){ echo $db->connect_errno.':'.$db->connect_error; } $stmt=$db->prepare("UPDATE staf SET salary=9000 WHERE staff_id=?;"); $stmt->bind_param("i",$id); $id=3; $stmt->execute(); echo '成功更新了'.$db->affected_rows.'条记录'; $stmt->close(); $db->close();
点击 "运行实例" 按钮查看在线实例
pdo_delete.php
<?php /医院 *简化预处理 */ $pdo=new PDO('mysql:dbname=user','root','root'); $id=8; //预处理语句 $sql="DELETE FROM staf WHERE staff_id=:id;"; $stmt=$pdo->prepare($sql); $stmt->bindParam(':id',$id,PDO::PARAM_INT); $stmt->execute(); echo '成功删除了'.$stmt->rowCount().'条记录';
点击 "运行实例" 按钮查看在线实例