list_database.class.php
来自「phpMyAdmin图形界面化操作,我已经配置好了,只要把解要压缩后的文件放到站」· PHP 代码 · 共 513 行 · 第 1/2 页
PHP
513 行
<?php/* vim: set expandtab sw=4 ts=4 sts=4: *//** * holds the PMA_List_Database class * * @version $Id: List_Database.class.php 12156 2008-12-25 14:00:56Z lem9 $ *//** * the list base class */require_once './libraries/List.class.php';/** * handles database lists * * <code> * $PMA_List_Database = new PMA_List_Database($userlink, $controllink); * </code> * * @todo this object should be attached to the PMA_Server object * @todo ? make use of INFORMATION_SCHEMA * @todo ? support --skip-showdatabases and user has only global rights * @access public * @since phpMyAdmin 2.9.10 *//*public*/ class PMA_List_Database extends PMA_List{ /** * @var mixed database link resource|object to be used */ protected $_db_link = null; /** * @var mixed user database link resource|object */ protected $_db_link_user = null; /** * @var mixed controluser database link resource|object */ protected $_db_link_control = null; /** * @var boolean whether SHOW DATABASES is disabled or not * @access protected */ protected $_show_databases_disabled = false; /** * @var string command to retrieve databases from server */ protected $_command = null; /** * Constructor * * @uses PMA_List_Database::$_db_link * @uses PMA_List_Database::$_db_link_user * @uses PMA_List_Database::$_db_link_control * @uses PMA_List_Database::build() * @param mixed $db_link_user user database link resource|object * @param mixed $db_link_control control database link resource|object */ public function __construct($db_link_user = null, $db_link_control = null) { $this->_db_link = $db_link_user; $this->_db_link_user = $db_link_user; $this->_db_link_control = $db_link_control; parent::__construct(); $this->build(); } /** * checks if the configuration wants to hide some databases * * @todo temporaly use this docblock to test how to doc $GLOBALS * @uses PMA_List_Database::$items * @uses preg_match() * @uses $cfg['Server']['hide_db'] */ protected function _checkHideDatabase() { if (empty($GLOBALS['cfg']['Server']['hide_db'])) { return; } foreach ($this->getArrayCopy() as $key => $db) { if (preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db)) { $this->offsetUnset($key); } } } /** * retrieves database list from server * * @todo we could also search mysql tables if all fail? * @uses PMA_List_Database::$_show_databases_disabled for not retrying if SHOW DATABASES is disabled * @uses PMA_List_Database::$_db_link * @uses PMA_List_Database::$_db_link_control in case of SHOW DATABASES is disabled for userlink * @uses PMA_DBI_fetch_result() * @uses PMA_DBI_getError() * @uses $GLOBALS['error_showdatabases'] * @uses $GLOBALS['errno'] * @param string $like_db_name usally a db_name containing wildcards */ protected function _retrieve($like_db_name = null) { if ($this->_show_databases_disabled) { return array(); } if (null !== $like_db_name) { $command = "SHOW DATABASES LIKE '" . $like_db_name . "'"; } elseif (null === $this->_command) { $command = str_replace('#user#', $GLOBALS['cfg']['Server']['user'], $GLOBALS['cfg']['Server']['ShowDatabasesCommand']); $this->_command = $command; } else { $command = $this->_command; } $database_list = PMA_DBI_fetch_result($command, null, null, $this->_db_link); PMA_DBI_getError(); if ($GLOBALS['errno'] !== 0) { // failed to get database list, try the control user // (hopefully there is one and he has SHOW DATABASES right) $this->_db_link = $this->_db_link_control; $database_list = PMA_DBI_fetch_result($command, null, null, $this->_db_link); PMA_DBI_getError(); if ($GLOBALS['errno'] !== 0) { // failed! we will display a warning that phpMyAdmin could not safely // retrieve database list, the admin has to setup a control user or // allow SHOW DATABASES $GLOBALS['error_showdatabases'] = true; $this->_show_databases_disabled = true; } } return $database_list; } /** * builds up the list * * @uses PMA_List_Database::$items to initialize it * @uses PMA_List_Database::_checkOnlyDatabase() * @uses PMA_List_Database::_retrieve() * @uses PMA_List_Database::_checkHideDatabase() * @uses array_values() * @uses natsort() * @uses $cfg['NaturalOrder'] */ public function build() { if (! $this->_checkOnlyDatabase()) { $items = $this->_retrieve(); if ($GLOBALS['cfg']['NaturalOrder']) { natsort($items); } $this->exchangeArray($items); } $this->_checkHideDatabase(); } /** * checks the only_db configuration * * @uses PMA_List_Database::$_show_databases_disabled * @uses PMA_List_Database::$items * @uses PMA_List_Database::_retrieve() * @uses PMA_unescape_mysql_wildcards() * @uses preg_match() * @uses array_diff() * @uses array_merge() * @uses is_array() * @uses strlen() * @uses is_string() * @uses $cfg['Server']['only_db'] * @return boolean false if there is no only_db, otherwise true */ protected function _checkOnlyDatabase() { if (is_string($GLOBALS['cfg']['Server']['only_db']) && strlen($GLOBALS['cfg']['Server']['only_db'])) { $GLOBALS['cfg']['Server']['only_db'] = array( $GLOBALS['cfg']['Server']['only_db'] ); } if (! is_array($GLOBALS['cfg']['Server']['only_db'])) { return false; } $items = array(); foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) { if ($each_only_db === '*' && ! $this->_show_databases_disabled) { // append all not already listed dbs to the list $items = array_merge($items, array_diff($this->_retrieve(), $items)); // there can only be one '*', and this can only be last break; } // check if the db name contains wildcard, // thus containing not escaped _ or % if (! preg_match('/(^|[^\\\\])(_|%)/', $each_only_db)) { // ... not contains wildcard $items[] = PMA_unescape_mysql_wildcards($each_only_db); continue; } if (! $this->_show_databases_disabled) { $items = array_merge($items, $this->_retrieve($each_only_db)); continue; } // @todo induce error, about not using wildcards with SHOW DATABASE disabled? } $this->exchangeArray($items); return true; } /** * returns default item * * @uses PMA_List::getEmpty() * @uses $GLOBALS['db'] * @uses strlen() * @return string default item */ public function getDefault() { if (strlen($GLOBALS['db'])) { return $GLOBALS['db']; } return $this->getEmpty(); } /** * returns array with dbs grouped with extended infos * * @uses $GLOBALS['PMA_List_Database'] * @uses $GLOBALS['cfgRelation']['commwork'] * @uses $cfg['ShowTooltip'] * @uses $cfg['LeftFrameDBTree'] * @uses $cfg['LeftFrameDBSeparator']
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?