PHP MySQL connection status using phpinfo

<?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.

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.
mysql installation by phpinfo

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";
 }

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

Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com











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