Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if PHP has been compiled --with-mysql [duplicate]

Tags:

php

mysql

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?

like image 603
qdot Avatar asked Jun 19 '12 08:06

qdot


3 Answers

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
like image 76
Stennie Avatar answered Oct 13 '22 17:10

Stennie


if (function_exists('mysql_connect')) ...
like image 8
deceze Avatar answered Oct 13 '22 18:10

deceze


I think you might be looking for phpinfo();

This shows the info about PHP configuration.

phpinfo — Outputs information about PHP's configuration

like image 3
Bono Avatar answered Oct 13 '22 18:10

Bono