Blogger Information
Blog 36
fans 0
comment 1
visits 28324
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PDO实现删除操作
其琛的博客
Original
750 people have browsed it

pdo删除代码

<?php
//1.连接数据库,
try {
    $pdo = new PDO('mysql:dbname=php','root','root');
} catch (PDOException $e) {
    exit($e->getMessage());
}
$sql = "DELETE FROM class WHERE class_id = :class_id ";
if($stmt = $pdo->prepare($sql)) {
    $param = ['class_id'=>3];
    if ($stmt -> execute($param)){
        if ($stmt->rowCount()>0) {
            echo '成功删除了'.$stmt->rowCount().'条记录';
        } else {
            echo '没有记录被删除';
        }
    } else {
        print_r($stmt->errorInfo());
        exit();
    }

}else {
    print_r($pdo->errorInfo());
    exit();
}


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