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.
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['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){}
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!