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
This commit is contained in:
Sebastian Mendel
2005-11-17 12:15:59 +00:00
parent 507ea546b8
commit f2e910543d
4 changed files with 85 additions and 48 deletions

View File

@@ -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 <lem9@users.sourceforge.net>
* tbl_properties_links.php: missing menu tabs

View File

@@ -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'] )
.' - <a href="./Documentation.html#faqmysql" target="documentation">'
.$GLOBALS['strDocu'] . '</a>';
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 );
}
}
?>

View File

@@ -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') . '<br />' . "\n"
. '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
exit;
}
// MySQL client API
if (!defined('PMA_MYSQL_CLIENT_API')) {
if (function_exists('mysql_get_client_info')) {

View File

@@ -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') . '<br />' . "\n"
. '<a href="./Documentation.html#faqmysql" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
exit;
}
// MySQL client API
if (!defined('PMA_MYSQL_CLIENT_API')) {
$client_api = explode('.', mysqli_get_client_info());