


How to use mysqli extension technology to view server connection error reports
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)
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()
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(); ?>
The output result is as follows:
(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(); ?>
The running result is as follows:
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When writing web applications using PHP, a MySQL database is often used to store data. PHP provides a way to interact with the MySQL database called MySQLi. However, sometimes when using MySQLi, you will encounter an error message, as shown below: PHPFatalerror:Calltoundefinedfunctionmysqli_connect() This error message means that PHP cannot find my

Solution to php unable to connect to mysqli: 1. Open the "php.ini" file; 2. Find "mysqli.reconnect"; 3. Change "mysqli.reconnect = OFF" to "mysqli.reconnect = on".

The running file of mysql is mysqld; mysqld is an executable file, which represents the Mysql server program. Executing this file can directly start a server process; and mysqld_safe is a startup script, which will indirectly call mysqld and also start a monitor. process.

PDOPDO is an object-oriented database access abstraction layer that provides a unified interface for PHP, allowing you to use the same code to interact with different databases (such as Mysql, postgresql, oracle). PDO hides the complexity of underlying database connections and simplifies database operations. Advantages and Disadvantages Advantages: Unified interface, supports multiple databases, simplifies database operations, reduces development difficulty, provides prepared statements, improves security, supports transaction processing Disadvantages: performance may be slightly lower than native extensions, relies on external libraries, may increase overhead, demo code uses PDO Connect to mysql database: $db=newPDO("mysql:host=localhost;dbnam

If you encounter the following error message when using PHP to connect to a MySQL database: PHPWarning:mysqli_connect():(HY000/2002):Connectionrefused, then you can try to solve this problem by following the steps below. To confirm whether the MySQL service is running normally, you should first check whether the MySQL service is running normally. If the service is not running or fails to start, it may cause a connection refused error. you can

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

When using the mysqli extension to connect and operate a MySQL database, you sometimes encounter the error PHPFatalerror:Calltoundefinedmethodmysqli::prepare(). This error is usually caused by the following reasons: PHP has insufficient support for the mysqli extension; the mysqli extension is not loaded or configured correctly; there are syntax errors in the PHP code; the MySQL server is not correctly configured or running

When developing websites using PHP, database operations are very common. MySQLi is an extension commonly used in PHP to operate MySQL databases. It provides a relatively complete object-oriented interface, procedural interface, and supports operations of prepared statements. But sometimes when we use mysqli's prepared statements, we will encounter such an error: PHPFatalerror:Calltoundefinedfunctionmysqli_stmt_bin
