Checks whether database extension is loaded
public static checkDbExtension ( string $extension = 'mysql' ) : boolean | ||
$extension | string | mysql extension to check |
return | boolean |
/** * Test database connection * * @param string $connect_type 'tcp' or 'socket' * @param string $host host name * @param string $port tcp port to use * @param string $socket socket to use * @param string $user username to use * @param string $pass password to use * @param string $error_key key to use in return array * * @return bool|array */ public static function testDBConnection($connect_type, $host, $port, $socket, $user, $pass = null, $error_key = 'Server') { // static::testPHPErrorMsg(); $error = null; $host = PMA_sanitizeMySQLHost($host); if (DatabaseInterface::checkDbExtension('mysqli')) { $socket = empty($socket) || $connect_type == 'tcp' ? null : $socket; $port = empty($port) || $connect_type == 'socket' ? null : $port; $extension = 'mysqli'; } else { $socket = empty($socket) || $connect_type == 'tcp' ? null : ':' . ($socket[0] == '/' ? '' : '/') . $socket; $port = empty($port) || $connect_type == 'socket' ? null : ':' . $port; $extension = 'mysql'; } if ($extension == 'mysql') { $conn = @mysql_connect($host . $port . $socket, $user, $pass); if (!$conn) { $error = __('Could not connect to the database server!'); } else { mysql_close($conn); } } else { $conn = @mysqli_connect($host, $user, $pass, null, $port, $socket); if (!$conn) { $error = __('Could not connect to the database server!'); } else { mysqli_close($conn); } } // static::testPHPErrorMsg(false); if (isset($php_errormsg)) { $error .= " - {$php_errormsg}"; } return is_null($error) ? true : array($error_key => $error); }
*/ include_once './libraries/dbi/DBIDummy.php'; $extension = new DBIDummy(); } else { /** * First check for the mysqli extension, as it's the one recommended * for the MySQL server's version that we support * (if PHP 7+, it's the only one supported) */ $extension = 'mysqli'; if (!DatabaseInterface::checkDbExtension($extension)) { $docurl = PMA\libraries\Util::getDocuLink('faq', 'faqmysql'); $doclink = sprintf(__('See %sour documentation%s for more information.'), '[a@' . $docurl . '@documentation]', '[/a]'); if (PMA_PHP_INT_VERSION < 70000) { $extension = 'mysql'; if (!PMA\libraries\DatabaseInterface::checkDbExtension($extension)) { // warn about both extensions missing and exit PMA_warnMissingExtension('mysqli|mysql', true, $doclink); } elseif (empty($_SESSION['mysqlwarning'])) { trigger_error(__('You are using the mysql extension which is deprecated in ' . 'phpMyAdmin. Please consider installing the mysqli ' . 'extension.') . ' ' . $doclink, E_USER_WARNING); // tell the user just once per session $_SESSION['mysqlwarning'] = true; } } else { // mysql extension is not part of PHP 7+, so warn and exit PMA_warnMissingExtension('mysqli', true, $doclink); } } /** * Including The DBI Plugin */
/** * Returs list of used PHP extensions. * * @return array of strings */ public static function listPHPExtensions() { $result = array(); if (DatabaseInterface::checkDbExtension('mysqli')) { $result[] = 'mysqli'; } else { $result[] = 'mysql'; } if (extension_loaded('curl')) { $result[] = 'curl'; } if (extension_loaded('mbstring')) { $result[] = 'mbstring'; } return $result; }