实例
<?php /** * Created by PhpStorm. *更新数据 */ $pdo = new PDO('mysql:host=localhost;dbname=data','root','root'); $sql = "update stu set name = :name ,address = :address where id = :id"; $stmt = $pdo->prepare($sql); //$data = [ // ['name'=>'王源','address'=>'四川','id' =>16], // ['name'=>'赵薇','address'=>'安徽','id'=>15] //]; $stmt->execute(['name'=>'赵薇','address'=>'安徽','id'=>15]); $stmt->execute(['name'=>'斯外戈','address'=>'湖北徽','id'=>14]); if($stmt->rowCount()>0) { echo '<h3>成功更新'.$stmt->rowCount().'条</h3>'; }else { echo '<h3>更新失败</h3>'; print_r($stmt->errorInfo()); exit; } //if($stmt->execute(['name'=>'王源','address'=>'四川','id' =>16])) //{ // echo '<h3>成功更新'.$stmt->rowCount().'条</h3>'; //}else //{ // echo '<h3>更新失败</h3>'; // print_r($stmt->errorInfo()); // exit; //} $stmt = null; $pdo = null;
运行实例 »
点击 "运行实例" 按钮查看在线实例