Blogger Information
Blog 40
fans 1
comment 0
visits 32708
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
软删除的学习
李明伟的博客
Original
602 people have browsed it

软删除——

<?php
    $pdo = new PDO('mysql:host=127.0.0.1;dbname=php','root','root');
    $sql = 'UPDATE  `staff` SET `is_show` = 0 where id = 2';
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    $sql = 'SELECT * FROM `staff` WHERE `is_show` = 1';
    $stmt = $pdo->prepare($sql);
    $stmt->execute();
    echo '<pre>';
    print_r($stmt->fetchAll(PDO::FETCH_ASSOC));
    //软删除
1.在表中添加一个字段,用来表示当前记录的显示状态——is_show。
2.通过更新的方式来模拟删除,改变is_show的值从而实现记录的隐藏。
3.在查询的时候,根据是否显示的标记字段,来过滤显示的结果。
?>

上述例子中通过is_show的值判断数据是否显示,在通过查询语句进行筛选,从而实现软删除的目的。



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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!