Home > Database > Mysql Tutorial > How to use mysqli extension technology to view server connection error reports

How to use mysqli extension technology to view server connection error reports

黄舟
Release: 2019-02-27 14:48:48
Original
2358 people have browsed it

How to use mysqli extension technology to view server connection error reports

As PHP’s golden partner MySQL database, developed in PHP projects It plays a decisive role in the process, not only because MySQL is completely free, but also completely cross-platform like PHP. However, in the actual project development process, connection errors between PHP and the MySQL database are inevitable. This example will explain how to detect such connection errors as early as possible.

Recommended related mysql video tutorials: "mysql tutorial"

In the previous article "Retrieval of database information through mysqli extension technology》, we introduced how to use mysqli extension to achieve database information retrieval, so our article mainly introduces mysqli extension technology to view server connection error reports~

Technical points

In mysqli extension technology, you can obtain error reports in two ways. The first is to directly obtain the cause of the error, and the second is to obtain the error number represented by the connection error.

To directly obtain the name of the error, you can use the function mysqli_connect_error(). The description of this function is as follows:

string mysqli_connect_error(mysqli link)
Copy after login

The mysqli_connect_error() function will return an error message, which corresponds to using mysqli extension technology to connect to MySQL. Database error.

To obtain the error number generated when connecting to the MySQL database, you can use the function mysqli_connect_errno(). The function is described as follows:

int mysqli_connect_errno()
Copy after login

If an error occurs when connecting to the MySQL database server, an error message will be generated. The message number corresponding to the error can be obtained by using this function.

1045: Access denied for user 'username'@'user password' (user password: YES)

The above error represents an incorrect user password input.

2005: Unknown MySQL server host 'MySQL database server name' (11004)

The above error represents an input error in the MySQL database server name

2013: Lost connection to MySQL server during query

The above error means that the connection to the MySQL database was lost while executing the query.

Implementation process

(1) Create a php file to establish a connection between PHP and the MySQL database, and enter the wrong user password . The code is as follows:

<?php
$conn = mysqli_connect("localhost","root","root1");
echo mysqli_connect_errno();
?>
Copy after login

The output result is as follows:

How to use mysqli extension technology to view server connection error reports

(2) Create a php file to establish a connection between PHP and the MySQL database, and enter the wrong user password. The code is as follows:

<?php
$conn = mysqli_connect("localhost","root","root1");
echo mysqli_connect_error();
?>
Copy after login

The running result is as follows:

How to use mysqli extension technology to view server connection error reports

Then the method of viewing the server connection error report with mysqli extension technology is introduced here, right? It's very simple. I believe everyone can understand it. In the next article, we will continue to explain mysqli expansion technology. For details, please read "Using mysqli expansion technology to implement multi-table queries"!

【Related tutorial recommendations】

1. Relevant topic recommendations: "php operating mysql database"

2.【 MYSQL Online Free Video Tutorial

3. Recommended related video courses: "Elementary MySQLi Extension Library Video Tutorial

The above is the detailed content of How to use mysqli extension technology to view server connection error reports. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template