PHP MySQL connection status using phpinfo

Check MySQL drivers directly

phpinfo() shows extensive server configuration and should only be used in a local or otherwise restricted development environment. The extension checks below answer the MySQL driver question without publishing a full diagnostic page.

<?php
if (extension_loaded('mysqli')) {
    echo 'MySQLi extension is available.';
}
if (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers(), true)) {
    echo 'PDO MySQL driver is available.';
}
?>

Avoid publishing an unrestricted phpinfo() page on a production server because it reveals detailed environment information.

<?php
// Full diagnostic: use locally only, then delete this file.
phpinfo();
?>
Sometime we have to ensure that mysql support is enabled inside php configuration and is working. Current PHP uses separate MySQLi and PDO MySQL drivers. Check which drivers are installed and enabled in your PHP environment; the old mysql_* extension was removed in PHP 7.

However we can check the status of mysql support by using phpinfo function before going for phpmyadmin or any other tools. This is what we will get if we scroll down a bit from phpinfo display screen.

The screenshot below is an example of a diagnostic display; driver and server versions depend on your own installation.
mysql installation by phpinfo

Example: Checking MySQL Version via phpinfo()

<?php
// Restrict the report to loaded modules (still local-only).
phpinfo(INFO_MODULES);
?>

Example: Verifying MySQLi Extension Availability

if (function_exists('mysqli_connect')) {
    echo "MySQLi extension is enabled.";
} else {
    echo "MySQLi extension is not enabled.";
}

Example: Displaying MySQLi Configuration

$mysqli = new mysqli("localhost", "username", "password", "database");
echo "MySQLi server version: " . $mysqli->server_info;
$mysqli->close();
The examples distinguish a driver-availability check from reading server-version information. Run full phpinfo() only in a restricted environment; never leave public diagnostic pages deployed.

PHP PDO

if (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers(), true)) {
    echo 'PDO MySQL driver is installed.';
} else {
    echo 'PDO MySQL driver is not installed.';
}

ini_get() ini_set() PHP Version PDO
Guide to installation and How to write our first PHP Script



Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer