Possible Duplicate:
Detecting mysql support in php
Is there a quick way to programmatically check whether this particular PHP installation has been compiled with support for MYSQL?
There are actually multiple modules supporting MySQL (mysql, mysqli, pdo_mysql, ...). MySQLi (improved) is generally recommended for more complete support of MySQL5 features versus the original mysql module. PDO (PHP data objects) is a database abstraction layer that provides an object oriented data abstraction.
You can use function_exists()
per the previous comments if you want to check for the existence of a specific function per module (mysql_connect, mysqli_connect, ...).
Alternatively, you can use the PHP function extension_loaded()
to check for the extension itself (module name matching the output from phpinfo() ):
<?php
if (extension_loaded('mysql') or extension_loaded('mysqli')) {
// Looking good
}
?>
From a command line prompt, you can list all compiled-in modules with:
php -m
If you're on a unix-ish system, use grep
to filter the output to MySQL-related modules:
php -m | grep -i mysql
If you're on Windows, use findstr
to filter the output to MySQL-related modules:
php -m | findstr -i mysql
if (function_exists('mysql_connect')) ...
I think you might be looking for phpinfo();
This shows the info about PHP configuration.
phpinfo — Outputs information about PHP's configuration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With