📄 database_interface.lib.php
字号:
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * Common Option Constants For DBI Functions * * @version $Id: database_interface.lib.php 11585 2008-09-15 12:03:45Z lem9 $ */if (! defined('PHPMYADMIN')) { exit;}/** * */// 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);/** * Checks one of the mysql extensions * * @param string $extension mysql extension to check */function PMA_DBI_checkMysqlExtension($extension = 'mysql') { if (! function_exists($extension . '_connect')) { return false; } return true;}/** * check for requested extension */if (! PMA_DBI_checkMysqlExtension($GLOBALS['cfg']['Server']['extension'])) { // if it fails try alternative extension ... // and display an error ... /** * @todo add different messages for alternative extension * and complete fail (no alternative extension too) */ $error = sprintf(PMA_sanitize($GLOBALS['strCantLoad']), $GLOBALS['cfg']['Server']['extension']) .' - <a href="./Documentation.html#faqmysql" target="documentation">' .$GLOBALS['strDocu'] . '</a>'; trigger_error($error, E_USER_ERROR); if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') { $alternativ_extension = 'mysqli'; } else { $alternativ_extension = 'mysql'; } if (! PMA_DBI_checkMysqlExtension($alternativ_extension)) { // if alternative fails too ... PMA_fatalError( sprintf($GLOBALS['strCantLoad'], $GLOBALS['cfg']['Server']['extension']) . ' - [a@./Documentation.html#faqmysql@documentation]' . $GLOBALS['strDocu'] . '[/a]'); } $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, usually 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)) { $found = array(); if (preg_match('&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', $server_language, $found)) { $server_language = $found[1]; } } if (! empty($server_language) && isset($encodings[$server_language])) { if (function_exists('iconv')) { if ((@stristr(PHP_OS, 'AIX')) && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) && (@strcasecmp(ICONV_VERSION, 'unknown') == 0)) { require_once './libraries/iconv_wrapper.lib.php'; $message = PMA_aix_iconv_wrapper($encodings[$server_language], $GLOBALS['charset'] . $GLOBALS['cfg']['IconvExtraParams'], $message); } else { $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 { /** * @todo lang not found, try all, what TODO ? */ } return $message;}/** * returns array with table names for given db * * @param string $database name of database * @param mixed $link mysql link resource|object * @return array tables names */function PMA_DBI_get_tables($database, $link = null){ return PMA_DBI_fetch_result('SHOW TABLES FROM ' . PMA_backquote($database) . ';', null, 0, $link, PMA_DBI_QUERY_STORE);}/** * usort comparison callback * * @param string $a first argument to sort * @param string $b second argument to sort * * @return integer a value representing whether $a should be before $b in the * sorted array or not * * @global string the column the array shall be sorted by * @global string the sorting order ('ASC' or 'DESC') * * @access private */function PMA_usort_comparison_callback($a, $b){ if ($GLOBALS['cfg']['NaturalOrder']) { $sorter = 'strnatcasecmp'; } else { $sorter = 'strcasecmp'; } // produces f.e.: // return -1 * strnatcasecmp($a["SCHEMA_TABLES"], $b["SCHEMA_TABLES"]) return ($GLOBALS['callback_sort_order'] == 'ASC' ? 1 : -1) * $sorter($a[$GLOBALS['callback_sort_by']], $b[$GLOBALS['callback_sort_by']]);} // end of the 'PMA_usort_comparison_callback()' function/** * returns array of all tables in given db or dbs * this function expects unquoted 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> * * @todo move into PMA_Table * @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 * @param integer $limit_offset zero-based offset for the count * @param boolean|integer $limit_count number of tables to return * @return array list of tables in given db(s) */function PMA_DBI_get_tables_full($database, $table = false, $tbl_is_group = false, $link = null, $limit_offset = 0, $limit_count = false){ require_once './libraries/Table.class.php'; if (true === $limit_count) { $limit_count = $GLOBALS['cfg']['MaxTableList']; } // prepare and check parameters if (! is_array($database)) { $databases = array($database); } else { $databases = $database; } $tables = array(); if (! $GLOBALS['cfg']['Server']['DisableIS']) { // 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` // // on non-Windows servers, // added BINARY in the WHERE clause to force a case sensitive // comparison (if we are looking for the db Aa we don't want // to find the db aa) $this_databases = array_map('PMA_sqlAddslashes', $databases); $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`, `AVG_ROW_LENGTH` AS `Avg_row_length`, `DATA_LENGTH` AS `Data_length`, `MAX_DATA_LENGTH` AS `Max_data_length`, `INDEX_LENGTH` AS `Index_length`, `DATA_FREE` AS `Data_free`, `AUTO_INCREMENT` AS `Auto_increment`, `CREATE_TIME` AS `Create_time`, `UPDATE_TIME` AS `Update_time`, `CHECK_TIME` AS `Check_time`, `TABLE_COLLATION` AS `Collation`, `CHECKSUM` AS `Checksum`, `CREATE_OPTIONS` AS `Create_options`, `TABLE_COMMENT` AS `Comment` FROM `information_schema`.`TABLES` WHERE ' . (PMA_IS_WINDOWS ? '' : 'BINARY') . ' `TABLE_SCHEMA` IN (\'' . implode("', '", $this_databases) . '\') ' . $sql_where_table; if ($limit_count) { $sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset; } $tables = PMA_DBI_fetch_result($sql, array('TABLE_SCHEMA', 'TABLE_NAME'), null, $link); unset($sql_where_table, $sql); } // If permissions are wrong on even one database directory, // information_schema does not return any table info for any database
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -