📄 database_interface.lib.php
字号:
<?php/* $Id: database_interface.lib.php,v 2.29 2005/11/18 13:35:06 lem9 Exp $ */// vim: expandtab sw=4 ts=4 sts=4:/** * Common Option Constants For DBI Functions */// PMA_DBI_try_query()define('PMA_DBI_QUERY_STORE', 1); // Force STORE_RESULT method, ignored by classic MySQL.define('PMA_DBI_QUERY_UNBUFFERED', 2); // Do not read whole query// PMA_DBI_get_variable()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/' . $GLOBALS['cfg']['Server']['extension'] . '.dbi.lib.php');/** * Common Functions */function PMA_DBI_query($query, $link = NULL, $options = 0) { $res = PMA_DBI_try_query($query, $link, $options) or PMA_mysqlDie(PMA_DBI_getError($link), $query); return $res;}/** * converts charset of a mysql message, usally coming from mysql_error(), * into PMA charset, usally UTF-8 * uses language to charset mapping from mysql/share/errmsg.txt * and charset names to ISO charset from information_schema.CHARACTER_SETS * * @uses $GLOBALS['cfg']['IconvExtraParams'] * @uses $GLOBALS['charset'] as target charset * @uses PMA_DBI_fetch_value() to get server_language * @uses preg_match() to filter server_language * @uses in_array() * @uses function_exists() to check for a convert function * @uses iconv() to convert message * @uses libiconv() to convert message * @uses recode_string() to convert message * @uses mb_convert_encoding() to convert message * @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 ( $server_language = PMA_DBI_fetch_value( 'SHOW VARIABLES LIKE \'language\';', 0, 1 ) ) { if ( preg_match( '&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', $server_language, $found = array() ) ) { $server_language = $found[1]; } } if ( ! empty( $server_language ) && isset( $encodings[$server_language] ) ) { if ( function_exists( 'iconv' ) ) { $message = iconv( $encodings[$server_language], $GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message); } elseif ( function_exists( 'recode_string' ) ) { $message = recode_string( $encodings[$server_language] . '..' . $GLOBALS['charset'], $message ); } elseif ( function_exists( 'libiconv' ) ) { $message = libiconv( $encodings[$server_language], $GLOBALS['charset'], $message ); } elseif ( function_exists( 'mb_convert_encoding' ) ) { // do not try unsupported charsets if ( ! in_array( $server_language, array( 'ukrainian', 'greek', 'serbian' ) ) ) { $message = mb_convert_encoding( $message, $GLOBALS['charset'], $encodings[$server_language] ); } } } else { // lang not found, try all // what TODO ? } return $message;}/** * returns array with database names * * @return array $databases */function PMA_DBI_get_dblist( $link = NULL ) { $dbs_array = PMA_DBI_fetch_result( 'SHOW DATABASES;', $link ); // Before MySQL 4.0.2, SHOW DATABASES could send the // whole list, so check if we really have access: if ( PMA_MYSQL_INT_VERSION < 40002 ) { foreach ( $dbs_array as $key => $db ) { if ( ! PMA_DBI_select_db( $db, $link ) ) { unset( $dbs_array[$key] ); } } // re-index values $dbs_array = array_values( $dbs_array ); } return $dbs_array;}function PMA_DBI_get_tables($database, $link = NULL) { $result = PMA_DBI_query('SHOW TABLES FROM ' . PMA_backquote($database) . ';', NULL, PMA_DBI_QUERY_STORE); $tables = array(); while (list($current) = PMA_DBI_fetch_row($result)) { $tables[] = $current; } PMA_DBI_free_result($result); return $tables;}/** * returns array of all tables in given db or dbs * this function expects unqoted names: * RIGHT: my_database * WRONG: `my_database` * WRONG: my\_database * if $tbl_is_group is true, $table is used as filter for table names * if $tbl_is_group is 'comment, $table is used as filter for table comments * * <code> * PMA_DBI_get_tables_full( 'my_database' ); * PMA_DBI_get_tables_full( 'my_database', 'my_table' ) ); * PMA_DBI_get_tables_full( 'my_database', 'my_tables_', true ) ); * PMA_DBI_get_tables_full( 'my_database', 'my_tables_', 'comment' ) ); * </code> * * @uses PMA_MYSQL_INT_VERSION * @uses PMA_DBI_fetch_result() * @uses PMA_escape_mysql_wildcards() * @uses PMA_backquote() * @uses is_array() * @uses addslashes() * @uses strpos() * @uses strtoupper() * @param string $databases database * @param string $table table * @param boolean|string $tbl_is_group $table is a table group * @param resource $link mysql link * @return array list of tbales in given db(s) */function PMA_DBI_get_tables_full( $database, $table = false, $tbl_is_group = false, $link = NULL ){ // prepare and check parameters if ( empty( $database ) ) { return false; } elseif ( false !== strpos( '`', $database ) ) { // found ` in name return false; } elseif ( false !== strpos( '\\', $database ) ) { // found \ in name return false; } if ( PMA_MYSQL_INT_VERSION >= 50002 ) { // get table information from information_schema if ( $table ) { if ( true === $tbl_is_group ) { $sql_where_table = 'AND `TABLE_NAME` LIKE \'' . PMA_escape_mysql_wildcards( addslashes( $table ) ) . '%\''; } elseif ( 'comment' === $tbl_is_group ) { $sql_where_table = 'AND `TABLE_COMMENT` LIKE \'' . PMA_escape_mysql_wildcards( addslashes( $table ) ) . '%\''; } else { $sql_where_table = 'AND `TABLE_NAME` = \'' . addslashes( $table ) . '\''; } } else { $sql_where_table = ''; } // for PMA bc: // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME` $sql = ' SELECT *, `TABLE_SCHEMA` AS `Db`, `TABLE_NAME` AS `Name`, `ENGINE` AS `Engine`, `ENGINE` AS `Type`, `VERSION` AS `Version`, `ROW_FORMAT` AS `Row_format`, `TABLE_ROWS` AS `Rows`,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -