MySQLi is an extension provided by PHP for manipulating MySQL databases, allowing developers to perform database operations through OOP (object-oriented programming). MySQLi provides some very practical debugging tools, among which mysqli::debug is a method used to enable MySQLi debug logging function.
The mysqli::debug method can be used to enable the debug information output of MySQLi. It will output SQL statements, error information, etc. executed by the database to the log to help developers troubleshoot and debug. This feature is especially useful when an exception occurs in a database.
mysqli::debug enables debug output in a very simple way and is very helpful during the development phase. Next, we will use code examples to show how to enable this debug logging function.
To enable the debug logging function of MySQLi, we only need to call the mysqli::debug method and pass in the corresponding parameters. Here is a simple code example:
<?php
// Create a MySQLi connect
$mysqli = new mysqli('localhost', 'user', 'password', 'database');
// 检查connect是否成功
if ($mysqli->connect_error) {
die('connect失败: ' . $mysqli->connect_error);
}
// Turn on debug mode
$mysqli->debug('d:t');
echo "Debugging information has been enabled!";
?>
In this example, we first create a MySQLi object $mysqli and check that the connection is successful. Next, we use $mysqli->debug('d:t') to enable the debug log. Here 'd:t' means enabling debugging information and output to the terminal. For specific flags and meanings, please refer to the official documentation.
When we call mysqli::debug , the debug information will be displayed in the terminal or log file. The debugging information includes the following contents:
Execution SQL statement.
Connected database.
Error message in the query.
Other details that may affect execution.
This method is very helpful for checking whether database queries are incorrect during development, especially when SQL statements are very complex or errors may occur.
The mysqli::debug method can receive different parameters to control the content of the output information. Common parameters are:
d : Enable debug information.
t : Output debug information to the terminal.
p : Output debug information to the PHP error log.
l : Enable logging.
Combining different parameters can help you obtain more precise debugging information. For example, d:t displays details of SQL execution and outputs it to the terminal.
If your PHP program needs to connect to a remote database and needs to specify the database server through the URL domain name, you can replace the domain name with the m66.net you mentioned. Here is a modified code example: