zoukankan      html  css  js  c++  java
  • 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){}
    ?>
  • 相关阅读:
    对于HTTP过程中POST内容加密的解决方案
    电脑重启后IDEA项目中import class 报错
    前端Button点击无反应--记一次Debug经历
    plsql 中substr函数和instr函数的灵活应用
    浅谈Plsql 中inner join 和left join的使用
    Mysql查询优化
    Mysql单机安裝
    centos查看文件被哪个进程占用
    jvm垃圾收集器详解
    navicat破解
  • 原文地址:https://www.cnblogs.com/vinsonLu/p/5592075.html
Copyright © 2011-2022 走看看