phpinfo() is useful for a broad configuration report, but an application can check the exact extensions it needs without exposing the full server configuration page.
<?php
if (extension_loaded('mysqli')) {
echo 'MySQLi extension is available.
';
}
if (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
echo phpinfo();
?>
Sometime we have to ensure that mysql support is enabled inside php configuration and is working. In higher version of PHP, mysql support is integrated so no need to manually enable them from config file.
phpinfo(INFO_MODULES); // Displays all PHP modules including MySQL version
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();
These examples show how to check MySQL version, verify MySQLi extension, and display MySQL configuration using `phpinfo()`.
if(in_array("mysql",PDO::getAvailableDrivers())){
echo " You have PDO for MySQL driver installed ";
}else{
echo "PDO driver for MySQL is not installed in your system";
}
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.