实例 更新一条数据
<?php //1.连接数据库 require 'mysqli_connect-1.php'; //2.准备SQL语句 $sql = "UPDATE user SET name=? WHERE id=?;"; //3.创建stmt对象 $stmt = mysqli_stmt_init($db); //4.检测SQL语句 mysqli_stmt_prepare($stmt, $sql); /* 5参数绑定 */ mysqli_stmt_bind_param($stmt, "si", $name,$id); $name = '杨康发'; $id = 2; /* 6执行SQL语句 */ mysqli_stmt_execute($stmt); echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录'; /* 7注销stmt对象 */ mysqli_stmt_close($stmt); /* 8关闭数据库连接 */ mysqli_close($db); ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例 删除一条数据
<?php //1.连接数据库 require 'mysqli_connect-1.php'; //2.准备SQL语句 $sql = "DELETE FROM `user` WHERE id=?;"; //3.创建stmt对象 $stmt = mysqli_stmt_init($db); //4.检测SQL语句 mysqli_stmt_prepare($stmt, $sql); /* 5参数绑定 */ mysqli_stmt_bind_param($stmt, "i", $id); $id = 3; /* 6执行SQL语句 */ mysqli_stmt_execute($stmt); echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录'; /* 7注销stmt对象 */ mysqli_stmt_close($stmt); /* 8关闭数据库连接 */ mysqli_close($db);
运行实例 »
点击 "运行实例" 按钮查看在线实例