W3docs

mysqli_dump_debug_info

Learn how mysqli_dump_debug_info() writes MySQLi connection debug info to the MySQL server log. Covers procedural and OO syntax, return values, and examples.

The PHP mysqli_dump_debug_info() function dumps low-level debugging information about a MySQLi connection into the MySQL server's error log. This page explains what the function does, when it is actually useful, its syntax in both procedural and object-oriented styles, and how to read the output it produces.

What mysqli_dump_debug_info() does

mysqli_dump_debug_info() asks the underlying MySQL client library to write internal connection-state information to the server's log file. The kind of detail it emits — open tables, cached objects, memory usage of the connection — is meant for the people who develop MySQL itself, not for everyday application debugging. In practice you will reach for it only when you are tracking down a hard-to-reproduce problem at the driver level.

The function takes a single argument, the MySQLi connection, and returns a boolean: true on success and false on failure. It does not return the debug text to your script; the information goes straight to the server log (the location depends on your MySQL configuration, often something like /var/log/mysql/error.log).

Syntax

There are two equivalent styles, because every MySQLi feature is available as both a procedural function and an object method.

// Procedural style
mysqli_dump_debug_info(mysqli $mysql): bool

// Object-oriented style
$mysqli->dump_debug_info(): bool
ParameterDescription
$mysqlA connection object returned by mysqli_connect(). Required in the procedural style.

The return value is true if the request to dump the information succeeded, and false otherwise.

Procedural example

The example below opens a connection, requests a debug dump, and reports whether the request succeeded. Replace the credentials with your own to run it against a real server.

Dumping debug info (procedural)

<?php
// Throw exceptions instead of warnings on connection errors
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = mysqli_connect("localhost", "user", "password", "my_database");

// Ask the client library to write debug info to the MySQL server log
if (mysqli_dump_debug_info($mysqli)) {
    echo "Debug information was dumped to the server log.\n";
} else {
    echo "Could not dump debug information.\n";
}

mysqli_close($mysqli);
?>

After running this, open the MySQL server's error log to read the dump. The function itself only tells you whether the request was accepted — the actual diagnostic text lives in the log.

Object-oriented example

If you prefer the object-oriented MySQLi API, call dump_debug_info() directly on the connection object.

Dumping debug info (object-oriented)

<?php
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

$mysqli = new mysqli("localhost", "user", "password", "my_database");

if ($mysqli->dump_debug_info()) {
    echo "Debug information was dumped to the server log.\n";
} else {
    echo "Could not dump debug information.\n";
}

$mysqli->close();
?>

Both styles do exactly the same thing; pick whichever matches the rest of your codebase.

When to use it (and when not to)

Reach for mysqli_dump_debug_info() only when you suspect a problem inside the MySQL connection layer itself — for example, leaked prepared statements or unexpected memory growth on a long-lived connection. For ordinary application debugging you almost always want something more targeted:

Note: the function only writes to the server log when the MySQL server has been built with debugging support and is configured to accept it. On a standard production build it may quietly do nothing useful, which is one more reason it is a specialist tool rather than a day-to-day one.

Conclusion

mysqli_dump_debug_info() is a narrow, low-level diagnostic that dumps internal MySQLi connection details into the MySQL server log and returns a boolean indicating whether the request succeeded. It is valuable for driver-level investigations but rarely the right tool for everyday work — for that, prefer mysqli_error(), connection statistics, or PHP's own error logging.

Practice

Practice
What does PHP's mysqli_dump_debug_info() function return?
What does PHP's mysqli_dump_debug_info() function return?
Was this page helpful?