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.
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.
We are running MySQLi 8.2.12 with PHP 8 , this is a part of the display of phpinfo function.
Example: Checking MySQL Version via phpinfo()
phpinfo(INFO_MODULES); // Displays all PHP modules including MySQL version
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();
These examples show how to check MySQL version, verify MySQLi extension, and display MySQL configuration using `phpinfo()`.
PHP PDO
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";
}