diff --git a/ChangeLog b/ChangeLog index 18b640b51..fb3e2af2b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -23,6 +23,11 @@ $Source$ - commented out some never used variables * main.php, libraries/common.lib.php, libraries/dbi/*: - added $GLOBALS['PMA_errors'] array + * libraries/database_interface.lib.php, libraries/dbi/*: + fall back to alternative mysql extension if selected fails and switch to + error.php if this fails too + - moved loading of extension out of libraries/dbi/* into + libraries/database_interface.lib.php 2005-11-16 Marc Delisle * tbl_properties_links.php: missing menu tabs diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 323930a7b..7d677c456 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -12,10 +12,71 @@ define('PMA_DBI_QUERY_UNBUFFERED', 2); // Do not read whole query define('PMA_DBI_GETVAR_SESSION', 1); define('PMA_DBI_GETVAR_GLOBAL', 2); +/** + * Loads the mysql extensions if it is not loaded yet + * + * @param string $extension mysql extension to load + */ +function PMA_DBI_checkAndLoadMysqlExtension( $extension = 'mysql' ) { + if ( ! function_exists( $extension . '_connect' ) ) { + PMA_dl( $extension ); + // check whether mysql is available + if ( ! function_exists( $extension . '_connect' ) ) { + return false; + } + } + + return true; +} + + +/** + * check for requested extension + */ +if ( ! PMA_DBI_checkAndLoadMysqlExtension( $GLOBALS['cfg']['Server']['extension'] ) ) { + + // if it fails try alternative extension ... + // and display an error ... + + // TODO 2.7.1: add different messages for alternativ extension + // and complete fail (no alternativ extension too) + $GLOBALS['PMA_errors'][] = + sprintf( PMA_sanitize( $GLOBALS['strCantLoad'] ), + $GLOBALS['cfg']['Server']['extension'] ) + .' - ' + .$GLOBALS['strDocu'] . ''; + + if ( $GLOBALS['cfg']['Server']['extension'] === 'mysql' ) { + $alternativ_extension = 'mysqli'; + } else { + $alternativ_extension = 'mysql'; + } + + if ( ! PMA_DBI_checkAndLoadMysqlExtension( $alternativ_extension ) ) { + // if alternativ fails too ... + header( 'Location: error.php' + . '?lang=' . urlencode( $available_languages[$lang][2] ) + . '&char=' . urlencode( $charset ) + . '&dir=' . urlencode( $text_dir ) + . '&type=' . urlencode( $strError ) + . '&error=' . urlencode( + sprintf( $GLOBALS['strCantLoad'], + $GLOBALS['cfg']['Server']['extension'] ) + .' - [a@./Documentation.html#faqmysql@documentation]' + .$GLOBALS['strDocu'] . '[/a]' ) + . '&' . SID + ); + exit(); + } + + $GLOBALS['cfg']['Server']['extension'] = $alternativ_extension; + unset( $alternativ_extension ); +} + /** * Including The DBI Plugin */ -require_once('./libraries/dbi/' . $cfg['Server']['extension'] . '.dbi.lib.php'); +require_once('./libraries/dbi/' . $GLOBALS['cfg']['Server']['extension'] . '.dbi.lib.php'); /** * Common Functions @@ -747,4 +808,5 @@ function PMA_DBI_get_default_engine() { return PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE \'table_type\';', 0, 1 ); } } -?> + +?> \ No newline at end of file diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index 6ab623001..c88f62469 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -6,21 +6,6 @@ * Interface to the classic MySQL extension */ -/** - * Loads the mysql extensions if it is not loaded yet - */ -if (!@function_exists('mysql_connect')) { - PMA_dl('mysql'); -} - -// check whether mysql is available -if (!@function_exists('mysql_connect')) { - require_once('./libraries/header_http.inc.php'); - echo sprintf($strCantLoad, 'mysql') . '
' . "\n" - . '' . $GLOBALS['strDocu'] . '' . "\n"; - exit; -} - // MySQL client API if (!defined('PMA_MYSQL_CLIENT_API')) { if (function_exists('mysql_get_client_info')) { @@ -69,7 +54,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { if (empty($link)) { PMA_auth_fails(); } // end if - + PMA_DBI_postConnect($link, $is_controluser); return $link; @@ -122,7 +107,7 @@ function PMA_mysql_fetch_array($result, $type = FALSE) { /* No data returned => do not touch it */ if (! $data) return $data; - + if (!defined('PMA_MYSQL_INT_VERSION') || PMA_MYSQL_INT_VERSION >= 40100 || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { /* No recoding -> return data as we got them */ @@ -169,7 +154,7 @@ function PMA_DBI_free_result($result) { /** * returns last error message or false if no errors occured - * + * * @uses PMA_MYSQL_INT_VERSION * @uses PMA_convert_display_charset() * @uses PMA_DBI_convert_message() @@ -184,7 +169,7 @@ function PMA_DBI_free_result($result) { * @return string|boolean $error or false */ function PMA_DBI_getError( $link = NULL ) { - unset( $GLOBALS['errno'] ); + unset( $GLOBALS['errno'] ); if ( NULL === $link && isset( $GLOBALS['userlink'] ) ) { $link =& $GLOBALS['userlink']; @@ -193,7 +178,7 @@ function PMA_DBI_getError( $link = NULL ) { // } else { // return FALSE; } - + if ( NULL !== $link ) { $error_number = mysql_errno( $link ); $error_message = mysql_error( $link ); @@ -205,13 +190,13 @@ function PMA_DBI_getError( $link = NULL ) { return false; } - // keep the error number for further check after the call to PMA_DBI_getError() + // keep the error number for further check after the call to PMA_DBI_getError() $GLOBALS['errno'] = $error_number; if ( ! empty( $error_message ) ) { $error_message = PMA_DBI_convert_message( $error_message ); } - + // Some errors messages cannot be obtained by mysql_error() if ( $error_number == 2002 ) { $error = '#' . ((string) $error_number) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem']; diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index a1ec0b722..03354721d 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -6,21 +6,6 @@ * Interface to the improved MySQL extension (MySQLi) */ -/** - * Loads the MySQLi extension if it is not loaded yet - */ -if (!@function_exists('mysqli_connect')) { - PMA_dl('mysqli'); -} - -// check whether mysql is available -if (!@function_exists('mysqli_connect')) { - require_once('./libraries/header_http.inc.php'); - echo sprintf($strCantLoad, 'mysqli') . '
' . "\n" - . '' . $GLOBALS['strDocu'] . '' . "\n"; - exit; -} - // MySQL client API if (!defined('PMA_MYSQL_CLIENT_API')) { $client_api = explode('.', mysqli_get_client_info()); @@ -59,7 +44,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { // NULL enables connection to the default socket $server_socket = (empty($cfg['Server']['socket'])) - ? NULL + ? NULL : $cfg['Server']['socket']; $link = mysqli_init(); @@ -133,7 +118,7 @@ function PMA_mysqli_fetch_array($result, $type = FALSE) { /* No data returned => do not touch it */ if (! $data) return $data; - + if (!defined('PMA_MYSQL_INT_VERSION') || PMA_MYSQL_INT_VERSION >= 40100 || !(isset($cfg['AllowAnywhereRecoding']) && $cfg['AllowAnywhereRecoding'] && $allow_recoding)) { /* No recoding -> return data as we got them */ @@ -204,7 +189,7 @@ function PMA_DBI_free_result($result) { /** * returns last error message or false if no errors occured - * + * * @uses PMA_MYSQL_INT_VERSION * @uses PMA_convert_display_charset() * @uses PMA_DBI_convert_message() @@ -222,7 +207,7 @@ function PMA_DBI_free_result($result) { */ function PMA_DBI_getError( $link = NULL ) { unset( $GLOBALS['errno'] ); - + if ( NULL === $link && isset( $GLOBALS['userlink'] ) ) { $link =& $GLOBALS['userlink']; // Do not stop now. We still can get the error code @@ -241,14 +226,14 @@ function PMA_DBI_getError( $link = NULL ) { if ( 0 == $error_number ) { return false; } - + // keep the error number for further check after the call to PMA_DBI_getError() $GLOBALS['errno'] = $error_number; if ( ! empty( $error_message ) ) { $error_message = PMA_DBI_convert_message( $error_message ); } - + if ( $error_number == 2002 ) { $error = '#' . ((string) $error_number) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem']; } elseif ( defined( 'PMA_MYSQL_INT_VERSION' ) && PMA_MYSQL_INT_VERSION >= 40100 ) { @@ -334,13 +319,13 @@ function PMA_DBI_get_fields_meta($result) { // this happens sometimes (seen under MySQL 4.0.25) if (!is_array($fields)) { - return FALSE; + return FALSE; } foreach ($fields as $k => $field) { $fields[$k]->type = $typeAr[$fields[$k]->type]; $fields[$k]->flags = PMA_DBI_field_flags($result, $k); - + // Enhance the field objects for mysql-extension compatibilty $flags = explode(' ', $fields[$k]->flags); array_unshift($flags, 'dummy'); @@ -362,7 +347,7 @@ function PMA_DBI_num_fields($result) { function PMA_DBI_field_len($result, $i) { $info = mysqli_fetch_field_direct($result, $i); - // stdClass::$length will be integrated in + // stdClass::$length will be integrated in // mysqli-ext when mysql4.1 has been released. return @$info->length; }