Home >Backend Development >PHP Tutorial >Some summaries and examples about php mysqli functions (4)

Some summaries and examples about php mysqli functions (4)

王林
王林Original
2019-08-16 18:06:552347browse

Foreword: PHP is a programming language that is relatively easy to get started with, and PHP has a lot of built-in functions. Therefore, it is particularly important to understand and master these built-in functions. Next we will analyze some of the built-in functions of PHP.

I will continue to organize it for you in the future.

Recommended related video tutorials: https://www.php.cn/course/list/29/type/4.html

About the understanding of phpMysqli functions:

1. What is php mysqli?

php mysqli = php nysqli improved

The mysqli function allows you to access the database server.

Notice! The mysqli extension is available for mysqli version 4.1.13 or newer.

2. How to use mysqli function?

If you want to use the mysqli function, you must add support for the mysqli extension when compiling php.

For more information about installation, please visit: http://www.php.net/manual/en/mysqli.installation.php

For details about running configuration Detailed information address: http://www.php.net/manual/en/mysqli.configuration.php

3. Introduction to php related functions

1, mysqli_debug(message)Function

Description: Used to perform debugging operations and return true.

Note; In order to use this function, you must compile the mysql client library to support debugging.

2, mysqli_dump_debug_info(link)Function

Description: Dump debugging information into the log, return true if successful, false if failed.

3, mysqli_error_list()Function

Description: Returns the error list of the recently called function, each error has an errno, error , associative array of sqlstate.

4, mysqli_state(connection)Function

Description: Return the current system state.

Example:

<?php
//配置数据库相关信息
$localhost = &#39;localhost&#39;;
$username = &#39;zmz&#39;;
$password = &#39;20040315&#39;;
$dbname = &#39;zmz&#39;;
$port = 3306;

//连接数据库
$conn = mysqli_connect($localhost,$username,$password,$dbname,$port);
//检查连接
if(mysqli_connect_errno($conn)) {
die(&#39;连接失败!&#39;.mysqli_connect_error());
}
//连接成功,返回当前系统状态
echo &#39;当前系统状态&#39;.mysqli_stat($conn);
//关闭连接
mysqli_close($conn);
?>

5, mysqli_fetch_all(result,resulttype)Function

Return typeresulttype:

MYSQLI_ASSOC

MYSQLI_NUM

MYSQLI_BOTH

Description: From Take all rows from the result set as an associative array or an indexed array or both.

Examples:

<?php
//配置数据库相关信息
$localhost = &#39;localhost&#39;;
$username = &#39;zmz&#39;;
$password = &#39;20040315&#39;;
$dbname = &#39;zmz&#39;;
$port = 3306;

//连接数据库
$conn = mysqli_connect($localhost,$username,$password,$dbname,$port);
//检查连接
if(mysqli_connect_errno($conn)) {
die(&#39;连接失败!&#39;.mysqli_connect_error());
}
//执行sql语句
$sql = "SELECT * FROM demo";
$result = mysqli_query($conn, $sql);
$rows = mysqli_fetch_all($result);
print_r($rows);
//释放结果集
mysqli_free_result($result);
//关闭连接
mysqli_close($conn);
?>

The above is the introduction and examples of phpmysqli functions compiled for you this time. I hope it can help you. Thanks!

Recommended related articles: https://www.php.cn/course/list/29/type/4.html

The above is the detailed content of Some summaries and examples about php mysqli functions (4). 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