php操作mysql 100行代码,增删查改

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <?php
        $con=mysqli_connect("ip地址",'root','000000');
        if($con){
            echo "数据库连接成功!<br/>";
        }else{
            echo "数据库连接失败!<br/>";
        }
        
        // $sql="create database test";执行一次就可以了
        // if(mysqli_query($con,$sql)){
        //     echo "数据库创建成功!<br />";
        // }else{
        //     echo "数据库创建失败!<br />";
        // }

        // mysqli_select_db($con,"test");
        // $table="create table testTable(
        //     student_id int(11) auto_increment primary key,
        //     student_no char(10) not null unique,
        //     student_name char(20) not null)";
        // if(mysqli_query($con,$table)){
        //     echo "数据表创建成功<br/>";
        // }else{
        //     echo "数据表创建失败<br/>". mysqli_error($con)."</br>";
        // }

        //  $mysqli=new mysqli('ip地址','root','000000','test');//这个是连接指定的数据库
        //  $query="select * from testTable";   //执行查询的语句

         //执行查询操作
        // $result=$mysqli->query($query);
        // foreach($result as $row){
        //     echo $row['student_id'].'&nbsp;&nbsp';
        //     echo $row['student_no'].'&nbsp;&nbsp';
        //     echo $row['student_name'].'<br>';
        // }



        //执行插入操作
        // $insertdatas=mysqli_query($mysqli,"insert into testTable(student_id,student_no,student_name) values('null','20190003','哦婆婆')");
        // $insertdatas=mysqli_query($mysqli,"insert into testTable(student_id,student_no,student_name) values('null','20190004','林ooo发p')");
        // if($insertdatas){
        //     echo "数据插入成功<br>";
            //  $result=$mysqli->query($query);

            //  foreach($result as $row){
            //      echo $row['student_id'].'&nbsp;&nbsp';
            //      echo $row['student_no'].'&nbsp;&nbsp';
            //      echo $row['student_name'].'<br>';
            // }
        // }else{
        //     echo "数据插入失败<br>". mysqli_error($con).'<br>';
        // }

        //接下来是更新操作
        // $up=mysqli_query($mysqli,"update testTable set student_no='20190010' where student_name='林'");
        // if($up){
        //     echo "数据更新成功<br>";
        //     $result=$mysqli->query($query);
        //     foreach($result as $row){
        //         echo $row['student_id'].'&nbsp;&nbsp;';
        //         echo $row['student_no'].'&nbsp;&nbsp';
        //         echo $row['student_name'].'<br>';
        //     }
        // }else{
        //     echo "数据更新失败<br>". mysqli_error($con). '<br>';
        // }
            
        //执行删除操作
        // $del=mysqli_query($mysqli,"delete from testTable where student_name='林'");
        // if($del){
        //     echo "数据库删除成功<br>";
        //     $result=$mysqli->query($query);
        //     foreach($result as $row){
        //         echo $row['student_id'].'&nbsp;&nbsp';
        //         echo $row['student_no']. '&nbsp;&nbsp';
        //         echo $row['student_name']. '<br>';
        //     }
        // }else{
        //     echo "数据删除失败<br>". mysqli_error($mysqli)."</br>";
        // }
        
        mysqli_close($mysqli);//关闭数据库连接


    ?>
</body>
</html>
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值