实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/26 * Time: 13:29 */ //1、连接数据库 require 'mysqli_config.php'; //2、执行查询 $sql = "update user set user_name = ? where user_id = 1 "; //3、 初始化stmt $stmt = $mysqli->stmt_init(); if ($stmt->prepare($sql)){ $stmt->bind_param('s',$user_name); //绑定参数 $user_name = '小王1'; $stmt->execute(); if ($stmt->affected_rows>0){ echo '<br>更新了'.$stmt->affected_rows.'条记录'; } else { echo '<br>无更新记录'; } }else { echo $stmt->error; } //关闭数据库 $mysqli->close();
运行实例 »
点击 "运行实例" 按钮查看在线实例
实例
<?php /医院 * Created by PhpStorm. * User: Administrator * Date: 2018/4/26 * Time: 14:58 */ //1.连接数据库,创建pdo对象 $pdo = new PDO('mysql:dbname=php','root','root'); //2、创建对象 $stmt = $pdo->prepare("delete from user where user_id=:user_id"); //3、绑定参数 $stmt -> execute(['user_id'=>1]); echo '成功更新了'.$stmt->rowCount().'条记录';
运行实例 »
点击 "运行实例" 按钮查看在线实例