bulicmatko
bulicmatko

Reputation: 356

Detecting mysql support in php

I want to get info about mysql support with PHP. I need a code to detect if server have mysql support.

Upvotes: 4

Views: 992

Answers (4)

XViD
XViD

Reputation: 306

if (extension_loaded('mysql')) {
    echo "MySQL Installed";
} else {
    echo "MySQL not installed";
}

Upvotes: 0

bcosca
bcosca

Reputation: 17555

if (extension_loaded('mysqlnd')) // or 'mysql' or 'pdo_*'
   echo 'MYSQL extension is loaded';

you can also use:

if (function_exists('mysql_connect'))
   echo 'MYSQL functions are available';

Upvotes: 8

Harmon Wood
Harmon Wood

Reputation: 2987

Do this in code with.

if (!function_exists('mysql_connect'))
{
  return 'MySQL not supported by PHP on this server!';
}

Upvotes: 1

Valentin Flachsel
Valentin Flachsel

Reputation: 10825

Save this as info.php (name not important though) and access it through a web browser. Amongst a bunch of other info, it will tell you whether PHP was compiled with MySQL or not.

<?php
phpinfo();
?>

Hope this helps.

Upvotes: 2

Related Questions