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.
<?php
// Restrict the report to loaded modules (still local-only).
phpinfo(INFO_MODULES);
?>
if (function_exists('mysqli_connect')) {
echo "MySQLi extension is enabled.";
} else {
echo "MySQLi extension is not enabled.";
}
$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.
if (class_exists('PDO') && in_array('mysql', PDO::getAvailableDrivers(), true)) {
echo 'PDO MySQL driver is installed.';
} else {
echo 'PDO MySQL driver is not installed.';
}
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.