Correction status:Uncorrected
Teacher's comments:
更新操作
<?php //链接数据库 require 'mysqli_connect.php'; //准备sql语句 $sql = "UPDATE staff set age=? where name=?;"; //创建stmt对象, $stmt =$mysqli->stmt_init(); //stmt检测对象的预处理语句是否正确s mysqli_stmt_prepare($stmt,$sql); //将变量与语句绑定 mysqli_stmt_bind_param($stmt,'is',$age,$name); $age=30;$name='小龙女'; //执行SQL mysqli_stmt_execute($stmt); //注销stmt mysqli_stmt_close($stmt); //关闭数据里链接 $mysqli->close(); ?>
点击 "运行实例" 按钮查看在线实例
删除操作
<?php //链接数据库 require 'mysqli_connect.php'; //准备sql语句 $sql = "DELETE from staff where name=?;"; //创建stmt对象, $stmt =$mysqli->stmt_init(); //stmt检测对象的预处理语句是否正确 mysqli_stmt_prepare($stmt,$sql); //将变量与语句绑定 mysqli_stmt_bind_param($stmt,'s',$name); $name='小龙女'; //执行SQL mysqli_stmt_execute($stmt); //注销stmt mysqli_stmt_close($stmt); //关闭数据里链接 $mysqli->close(); ?>
点击 "运行实例" 按钮查看在线实例