Home >Backend Development >PHP Problem >How to query the database with php mysqli

How to query the database with php mysqli

藏色散人
藏色散人Original
2021-06-26 09:48:423037browse

php Mysqli query database method: first generate a connection through mysqli; then obtain the query results through the select statement; and finally retrieve the records through the while loop.

How to query the database with php mysqli

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How does php mysqli query the database?

phpmysqli connection query data

mysqli:

<?php 
$code = $_POST[&#39;code&#39;];
$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` = &#39;$code&#39; limit 1";
    $result=$db_connect->query($strsql);
    // 循环取出记录
    while ($row=mysqli_fetch_assoc($result))
    {
     $status = $row[&#39;status&#39;];
     $scookies = $row[&#39;scookies&#39;];
    }
    // 释放资源
    $result->close();
    // 关闭连接
    $db_connect->close();
    if($status=="已付款"){
        $success = "success";
    }
    else{
        $success = "faild";
    } 
    echo $success.";".$scookies;
}
catch (Exception $e){}

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to query the database with php mysqli. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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