Reputation: 91
How can I do that? like:
if (mysql is available) {
connect and do queries
}
else {
use files
}
Upvotes: 2
Views: 7106
Reputation: 7478
Not that elegant:
if (shell_exec('mysql -V') != ''){
echo "MySql is here";
}else{
echo "No MySql here";
}
You may search for mysql in the string that "shell_exec('mysql -V')" will return.
Upvotes: 4
Reputation: 2610
Or use the phpinfo() function and search "mysql" with CTRL+F and check if the extension is activated...
Upvotes: 1
Reputation: 16953
I can't test this, but
if (function_exists('mysql_connect'))
may work.
Upvotes: 2
Reputation: 160863
Just try to connect and if fail then do other thing.
eg:
if ($link = mysql_connect('localhost', 'mysql_user', 'mysql_password')) {
//do queries
} else {
//use files
}
Upvotes: 0
Reputation: 5547
Have you tried:
extension_loaded("mysql");
http://us.php.net/extension_loaded
Upvotes: 3