- added PMA_DBI_convert_message()

- bug #1344654 Not converted mysql error message to chosen user language
This commit is contained in:
Sebastian Mendel
2005-11-06 12:14:43 +00:00
parent 087e3895dd
commit 4d7765c6c2
4 changed files with 170 additions and 56 deletions

View File

@@ -5,6 +5,12 @@ phpMyAdmin - Changelog
$Id$
$Source$
2005-11-06 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* libraries/database_interface.lib.php,
libraries/dbi/*.dbi.lib.php:
- added PMA_DBI_convert_message()
- bug #1344654 Not converted mysql error message to chosen user language
2005-11-05 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* themes/*/css/theme_right.css.php:
dropped deprecated style classes

View File

@@ -26,6 +26,78 @@ function PMA_DBI_query($query, $link = NULL, $options = 0) {
return $res;
}
/**
* converts charset in message, usally from mysql_error(),
* into PMA charset, usally UTF-8
*
* @uses $GLOBALS['cfg']['IconvExtraParams']
* @uses PMA_DBI_fetch_value()
* @uses preg_match()
* @uses in_array()
* @uses function_exists()
* @uses iconv()
* @uses libiconv()
* @uses recode_string()
* @uses mb_convert_encoding()
* @param string $message
* @return string $message
*/
function PMA_DBI_convert_message( $message ) {
// latin always last!
$encodings = array(
'japanese' => 'EUC-JP', //'ujis',
'japanese-sjis' => 'Shift-JIS', //'sjis',
'korean' => 'EUC-KR', //'euckr',
'russian' => 'KOI8-R', //'koi8r',
'ukrainian' => 'KOI8-U', //'koi8u',
'greek' => 'ISO-8859-7', //'greek',
'serbian' => 'CP1250', //'cp1250',
'estonian' => 'ISO-8859-13', //'latin7',
'slovak' => 'ISO-8859-2', //'latin2',
'czech' => 'ISO-8859-2', //'latin2',
'hungarian' => 'ISO-8859-2', //'latin2',
'polish' => 'ISO-8859-2', //'latin2',
'romanian' => 'ISO-8859-2', //'latin2',
'spanish' => 'CP1252', //'latin1',
'swedish' => 'CP1252', //'latin1',
'italian' => 'CP1252', //'latin1',
'norwegian-ny' => 'CP1252', //'latin1',
'norwegian' => 'CP1252', //'latin1',
'portuguese' => 'CP1252', //'latin1',
'danish' => 'CP1252', //'latin1',
'dutch' => 'CP1252', //'latin1',
'english' => 'CP1252', //'latin1',
'french' => 'CP1252', //'latin1',
'german' => 'CP1252', //'latin1',
);
if ( $lang = PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE \'language\';', 0, 1 ) ) {
if ( preg_match( '&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', $lang, $found = array() ) ) {
$lang = $found[1];
}
}
if ( ! empty( $lang ) && isset( $encodings[$lang] ) ) {
if ( function_exists( 'iconv' ) ) {
$message = iconv($encodings[$lang], 'UTF-8' . $GLOBALS['cfg']['IconvExtraParams'], $message);
} elseif ( function_exists( 'recode_string' ) ) {
$message = recode_string($encodings[$lang] . '..' . 'UTF-8', $message);
} elseif ( function_exists( 'libiconv' ) ) {
$message = libiconv($encodings[$lang], 'UTF-8', $message);
} elseif ( function_exists( 'mb_convert_encoding' ) ) {
// do not try unsupported charsets
if ( ! in_array( $lang, array( 'ukrainian', 'greek', 'serbian' ) ) ) {
$message = mb_convert_encoding( $message, 'UTF-8', $encodings[$lang] );
}
}
} else {
// lang not found, try all
// what TODO ?
}
return $message;
}
/**
* returns array with database names
*

View File

@@ -167,43 +167,60 @@ function PMA_DBI_free_result($result) {
}
}
function PMA_DBI_getError($link = NULL) {
unset($GLOBALS['errno']);
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
/**
* 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()
* @uses $GLOBALS['errno']
* @uses $GLOBALS['userlink']
* @uses $GLOBALS['strServerNotResponding']
* @uses $GLOBALS['strSocketProblem']
* @uses mysql_errno()
* @uses mysql_error()
* @uses defined()
* @param resource $link mysql link
* @return string|boolean $error or false
*/
function PMA_DBI_getError( $link = NULL ) {
unset( $GLOBALS['errno'] );
if ( NULL === $link && isset( $GLOBALS['userlink'] ) ) {
$link =& $GLOBALS['userlink'];
// Do not stop now. On the initial connection, we don't have a $link,
// we don't have a $GLOBALS['userlink'], but we can catch the error code
// } else {
// } else {
// return FALSE;
}
}
if (mysql_errno()) {
$error = mysql_errno();
if ( NULL !== $link ) {
$error_number = mysql_errno( $link );
$error_message = mysql_error( $link );
} else {
$error_number = mysql_errno();
$error_message = mysql_error();
} elseif ($link) {
$error = mysql_errno($link);
$error_message = mysql_error($link);
}
if ( 0 == $error_number ) {
return false;
}
// keep the error number for further check after the call to PMA_DBI_getError()
if (isset($error) && $error) {
$GLOBALS['errno'] = $error;
} else {
return FALSE;
}
$GLOBALS['errno'] = $error_number;
// Some errors messages cannot be obtained by mysql_error()
if ($error && $error == 2002) {
$error = '#' . ((string) $error) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem'];
} elseif ($error && $error == 2003) {
$error = '#' . ((string) $error) . ' - ' . $GLOBALS['strServerNotResponding'];
} elseif ($error && defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) {
$error = '#' . ((string) $error) . ' - ' . $error_message;
} elseif ($error) {
$error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset($error_message);
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'];
} elseif ( $error_number == 2003 ) {
$error = '#' . ((string) $error_number ) . ' - ' . $GLOBALS['strServerNotResponding'];
} elseif ( defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100 ) {
$error = '#' . ((string) $error_number ) . ' - ' . $error_message;
} else {
$error = '#' . ((string) $error_number ) . ' - ' . PMA_convert_display_charset( $error_message );
}
return $error;
}

View File

@@ -202,40 +202,59 @@ function PMA_DBI_free_result($result) {
}
}
function PMA_DBI_getError($link = NULL) {
unset($GLOBALS['errno']);
if (empty($link)) {
if (isset($GLOBALS['userlink'])) {
$link = $GLOBALS['userlink'];
// Do not stop now. We still can get the error code
// with mysqli_connect_errno()
// } else {
// return FALSE;
}
/**
* 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()
* @uses $GLOBALS['errno']
* @uses $GLOBALS['userlink']
* @uses $GLOBALS['strServerNotResponding']
* @uses $GLOBALS['strSocketProblem']
* @uses mysqli_errno()
* @uses mysqli_error()
* @uses mysqli_connect_errno()
* @uses mysqli_connect_error()
* @uses defined()
* @param resource $link mysql link
* @return string|boolean $error or false
*/
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
// with mysqli_connect_errno()
// } else {
// return false;
}
if (mysqli_connect_errno()) {
$error = mysqli_connect_errno();
$error_message = mysqli_connect_error();
} elseif ( !empty($link) && mysqli_errno($link)) {
$error = mysqli_errno($link);
$error_message = mysqli_error($link);
}
// keep the error number for further check after the call to PMA_DBI_getError()
if (!empty($error)) {
$GLOBALS['errno'] = $error;
if ( NULL !== $link ) {
$error_number = mysqli_errno( $link );
$error_message = mysqli_error( $link );
} else {
return FALSE;
$error_number = mysqli_connect_errno();
$error_message = mysqli_connect_error();
}
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 ($error && $error == 2002) {
$error = '#' . ((string) $error) . ' - ' . $GLOBALS['strServerNotResponding'] . ' ' . $GLOBALS['strSocketProblem'];
} elseif ($error && defined('PMA_MYSQL_INT_VERSION') && PMA_MYSQL_INT_VERSION >= 40100) {
$error = '#' . ((string) $error) . ' - ' . $error_message;
} elseif ($error) {
$error = '#' . ((string) $error) . ' - ' . PMA_convert_display_charset($error_message);
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 ) {
$error = '#' . ((string) $error_number) . ' - ' . $error_message;
} else {
$error = '#' . ((string) $error_number) . ' - ' . PMA_convert_display_charset($error_message);
}
return $error;
}