Blogger Information
Blog 48
fans 0
comment 0
visits 36391
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
pdo更新数据-2018.08.30
雨天的博客
Original
838 people have browsed it

实例

<?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;

运行实例 »

点击 "运行实例" 按钮查看在线实例


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!