Home > php教程 > php手册 > PHP+MySQL删除操作实例,phpmysql删除实例

PHP+MySQL删除操作实例,phpmysql删除实例

WBOY
Release: 2016-06-16 09:16:39
Original
806 people have browsed it

PHP+MySQL删除操作实例,phpmysql删除实例

本文实例讲述了PHP+MySQL删除操作的使用技巧。分享给大家供大家参考。具体如下:

复制代码 代码如下:


删除记录

 
    //连接数据库的参数 
    $host = "localhost"; 
    $user = "root"; 
    $pass = "zq19890319"; 
    $db = "phpdev"; 
    //创建mysqli对象 
    //打开一个数据库连接 
    $mysqli = new mysqli($host, $user, $pass, $db); 
    //检查连接错误 
    if(mysqli_connect_errno()){ 
        die("Unable to connect!"); 
    } 
    //如果记录ID存在,则执行删除操作 
    if(isset($_GET['id'])){ 
        //构造删除记录的SQL 
        $query = "DELETE FROM symbols WHEREid = ".$_GET['id']; 
         
        //执行SQL查询 
        if($mysqli->query($query)){ 
            //显示删除后影响的记录数 
            echo $mysqli->affected_rows. "row(s) affected"; 
        } 
        else 
        { 
            //如果没有匹配的记录,显示数据库返回的错误信息 
            echo "Error in query : $query. ".$mysqli->error; 
        } 
    } 
    //构造显示删除后的记录 
    $query = "SELECT * FROM symbols"; 
    //执行该查询 
    if($result=$mysqli->query($query)){ 
        //显示返回的记录集行数 
        if($result->num_rows>0){ 
            //如果有记录 
            //显示记录集中列的内容 
            echo ""; 
            while($row=$result->fetch_array()){ 
                echo ""; 
                echo ""; 
                echo ""; 
                echo ""; 
                echo ""; 
                echo ""; 
            } 
        } 
        //释放对象所占用的内存 
        $result->close(); 
    } 
    else 
    { 
        //输出数据库错误的信息 
        echo "Error in query: $query. ".$mysqli->error; 
    } 
    //关闭数据库 
    $mysqli->close(); 
?>

希望本文所述对大家的php程序设计有所帮助。

".$row[0]."".$row[1]."".$row[2]."删除
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template