Check MySQLi Installation and Support

Check whether MySQLi is available

Use extension_loaded() to verify that the MySQLi extension is available in the current PHP runtime.

<?php
if (extension_loaded('mysqli')) {
    echo 'MySQLi is available';
    echo '<br>Client: ' . mysqli_get_client_info();
} else {
    echo 'MySQLi is not enabled';
}
?>

Checking PHP Installation

Use phpinfo() function to get details of your PHP installation. You should able to read this part from the output.


Using function_exists to check mysqli support
if (function_exists('mysqli_connect')) {
  echo "mysqli is installed";
}else{
echo " Enable Mysqli support in your PHP installation "; 
}

Download files to test your MySQLI support


Podcast on MySQL database management using MySQLi connector

How to enable MySQLi inside php.ini file

Open your php.ini file ( php configuration file ) inside your PHP directory ( or windows directory ) . Search for mysqli and enable the dll by removing ; before it. You may have to re-boot your system. Here is an image of two lines after removing ; inside php.ini file.

php.ini mysqli dll

Example 2: Checking MySQLi Installation via PHP Script

You can verify MySQLi installation by running a simple PHP script. This script will confirm if the MySQLi extension is enabled:

<?php
if (function_exists('mysqli_connect')) {
    echo "MySQLi is installed and working.";
} else {
    echo "MySQLi is not installed.";
}
?>

Example 3: Testing a Connection to MySQL Database

Once installed, you can create a basic connection to the MySQL database using MySQLi:

<?php
$host = "localhost";
$user = "root";
$pass = "password";
$db = "test_db";
$connection = mysqli_connect($host, $user, $pass, $db);
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully!";
?>

Configuration note

MySQLi must be installed and enabled by the PHP runtime or hosting environment. It cannot be enabled for the first time with ini_set() inside a script. On managed hosting, use the provider's PHP extension selector or contact the host; on your own server, install the matching PHP MySQL package and restart the relevant PHP/web service if required.

Additional Installation Tip: Installing MySQLi via Command Line

On systems you administer, install the MySQL extension package that matches your PHP version. Package names vary by operating system and repository; verify the package for your installed PHP version.

// For Ubuntu/Debian
sudo apt-get install php-mysqli

Example 4: Enabling MySQLi in php.ini

Ensure that the MySQLi extension is enabled in your *php.ini* configuration file:

extension=mysqli

MYSQLI Functions mysqli_connect(): Connection string for MYSQLI


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