Blogger Information
Blog 33
fans 0
comment 0
visits 24493
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PDO实现删除操作--2018.03.05上传
张鑫的博客
Original
599 people have browsed it

总结:pdo预处理技术实现删除操作

  1. 连接数据库

  2. 准备sql语句

  3. 创建预处理对象,把当前的sql语句抽象成一个对象

  4. 参数绑定

  5. 给参数赋值

  6. 执行删除操作

  7. 销毁对象

    代码演示:   


  8. 实例

    <?php
    // 1.连接数据库
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=demo','root','root');
    // 2.准备sql语句
    $sql="DELETE FROM student WHERE id=:id";
    // 3.创建预处理对象,把当前的sql语句抽象成一个对象
    $stmt = $pdo->prepare($sql);
    // 4.参数绑定
    $stmt->bindParam(':id',$id,PDO::PARAM_INT);
    // 5.给参数赋值
    $id = 3;
    // 6.执行删除操作
    if($stmt->execute()){
    	echo '成功删除了'.$stmt->rowCount().'条记录';
    }else{
    	echo '删除失败';
    	print_r($stmt->errorInfo());
    	exit();
    }
    
    // 7.销毁对象
    $pdo = null;

    运行实例 »

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

Correction status:qualified

Teacher's comments:
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