实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/25 * Time: 10:17 */ //1、连接数据库 require 'mysqli_config.php'; //2、执行查询 $con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME); $sql = "update user set user_name = ? where user_id = 1 "; $user_name = '王老师4'; //创建对象 $stmt = mysqli_stmt_init($con); if (mysqli_stmt_prepare($stmt,$sql)){ //参数绑定 mysqli_stmt_bind_param($stmt,"s",$user_name); //执行语句 mysqli_stmt_execute($stmt); echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录'.mysqli_stmt_insert_id($stmt); } //注销对象 mysqli_stmt_close($stmt); //关闭数据库 mysqli_close($con);
运行实例 »
点击 "运行实例" 按钮查看在线实例
删除:
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/25 * Time: 11:46 */ require 'mysqli_config.php'; //2、执行查询 $con = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME); $sql = "delete from user where user_id=? "; //创建对象 $stmt = mysqli_stmt_init($con); if (mysqli_stmt_prepare($stmt,$sql)){ //执行语句 $user_id = 1; mysqli_stmt_execute($stmt); echo '<br>更新了'.mysqli_stmt_affected_rows($stmt).'条记录'; } //注销对象 mysqli_stmt_close($stmt); //关闭数据库 mysqli_close($con);
运行实例 »
点击 "运行实例" 按钮查看在线实例