• php使用mysql和mysqli连接查询数据


    mysql:

    <?php 
    $code = $_POST['code'];
    $status = "";
    $success = "";
    $scookies = "";
    
    try {
        $dbname="root";
        $dbpass="root";
        $dbhost="127.0.0.1";
        $dbdatabase="mysql";
     
        //生成一个连接
        $db_connect=mysql_connect($dbhost,$dbname,$dbpass);
    
        //选择一个需要操作的数据库
        mysql_select_db($dbdatabase,$db_connect);
    
        // 获取查询结果
        $strsql="select * from `go_member_addmoney_record` where `code` = '$code' limit 1";
        $result=mysql_query($strsql);
    
        // 循环取出记录
        while ($row=mysql_fetch_array($result))
        {
            $status = $row['status'];
            $scookies = $row['scookies'];
        }
    
        // 释放资源
        mysql_free_result($result);
        // 关闭连接
        mysql_close($db_connect);  
    
        if($status=="已付款"){
            $success = "success";
        }
        else{
            $success = "faild";
        } 
        echo $success.";".$scookies;
    }
    catch (Exception $e){}
    ?>

    mysqli:

    <?php 
    $code = $_POST['code'];
    $status = "";
    $success = "";
    $scookies = "";
    
    try {
        $dbname="root";
        $dbpass="root";
        $dbhost="127.0.0.1";
        $dbdatabase="mysql";
     
        //生成一个连接
        $db_connect= new mysqli($dbhost,$dbname,$dbpass,$dbdatabase);
    
        // 获取查询结果
        $strsql="select * from `go_member_addmoney_record` where `code` = '$code' limit 1";
        $result=$db_connect->query($strsql);
    
        // 循环取出记录
        while ($row=mysqli_fetch_assoc($result))
        {
         $status = $row['status'];
         $scookies = $row['scookies'];
        }
        // 释放资源
        $result->close();
        // 关闭连接
        $db_connect->close();
    
        if($status=="已付款"){
            $success = "success";
        }
        else{
            $success = "faild";
        } 
        echo $success.";".$scookies;
    }
    catch (Exception $e){}
    ?>
  • 相关阅读:
    Windows下sc create命令行注册服务
    FluentValidation .NET 验证组件
    Linux系统下安装Redis
    mysql的sql_mode设置
    Linux系统下安装rocketmq
    Windows系统中Nacos的下载安装及使用
    配置Mysql允许远程访问
    Sqlserver 获取每周的数据
    如何在Mac OS X上构建ClickHouse
    Mac 设置 JAVA_HOME 环境变量
  • 原文地址:https://www.cnblogs.com/vinsonLu/p/5592075.html
Copyright © 2020-2023  润新知