Check if PHP --with-mysql compiled

Possible duplicate:
Mysql support detection in php

Is there a quick way to programmatically check if this particular PHP installation has been compiled with MYSQL support?

+4
source share
4 answers
if (function_exists('mysql_connect')) ... 
+6
source

In fact, there are several modules that support MySQL (mysql, mysqli, pdo_mysql, ...). MySQLi (enhanced) is usually recommended for more complete support for MySQL5 functions compared to the mysql source module. PDO (PHP Data Objects) is a database abstraction layer that provides object-oriented data abstraction.

You can use function_exists() for previous comments if you want to check for a specific function for each module (mysql_connect, mysqli_connect, ...).

Alternatively, you can use the PHP extension_loaded() function to check the extension itself (module name corresponding to phpinfo () output)

 <?php if (extension_loaded('mysql') or extension_loaded('mysqli')) { // Looking good } ?> 

At the command line, you can list all compiled modules with:

 php -m 

If you use a unix-ish system, use grep to filter output to MySQL-related modules:

 php -m | grep -i mysql 

If you are running on Windows, use findstr to filter output to MySQL-related modules:

 php -m | findstr -i mysql 
+7
source

I think you can look for phpinfo ();

Information about setting up PHP is displayed here.

phpinfo - displays PHP configuration information

+3
source

Yes there is. Just check if one of the mysql_* functions mysql_* , say mysql_connect :

 if (function_exists("mysql_connect")) { echo "compiled using --with-mysql\n"; } 
+2
source

All Articles