📄 pma_list_database.class.php
字号:
<?php/** * holds the PMA_List_Database class * *//** * the list base class */require_once './libraries/PMA_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 * @access protected */ var $_db_link = null; /** * @var mixed user database link resource|object * @access protected */ var $_db_link_user = null; /** * @var mixed controluser database link resource|object * @access protected */ var $_db_link_control = null; /** * @var boolean whether SHOW DATABASES is disabled or not * @access protected */ var $_show_databases_disabled = false; /** * 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 */ 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; $this->build(); } /** * old PHP 4 style constructor * * @see PMA_List_Database::__construct() */ function PMA_List_Database($db_link_user = null, $db_link_control = null) { $this->__construct($db_link_user, $db_link_control); } /** * removes all databases not accessible by current user from list * * @access protected * @uses PMA_List_Database::$items * @uses PMA_List_Database::$_db_link_user * @uses PMA_List_Database::$_need_to_reindex to set it if reuqired * @uses PMA_DBI_select_db() */ function _checkAccess() { foreach ($this->items as $key => $db) { if (! @PMA_DBI_select_db($db, $this->_db_link_user)) { unset($this->items[$key]); } } // re-index values $this->_need_to_reindex = true; } /** * checks if the configuration wants to hide some databases * * @todo temporaly use this docblock to test how to doc $GLOBALS * @access protected * @uses PMA_List_Database::$items * @uses PMA_List_Database::$_need_to_reindex to set it if reuqired * @uses preg_match() * @uses $GLOBALS['cfg'] * @uses $GLOBALS['cfg']['Server'] * @uses $GLOBALS['cfg']['Server']['hide_db'] * @global array $GLOBALS['cfg'] * @global array $cfg */ function _checkHideDatabase() { if (empty($GLOBALS['cfg']['Server']['hide_db'])) { return; } foreach ($this->items as $key => $db) { if (preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db)) { unset($this->items[$key]); } } // re-index values $this->_need_to_reindex = true; } /** * retrieves database list from server * * @todo we could also search mysql tables if all fail? * @access protected * @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() * @global boolean $error_showdatabases to alert not allowed SHOW DATABASE * @global integer $errno from PMA_DBI_getError() * @param string $like_db_name usally a db_name containing wildcards */ function _retrieve($like_db_name = '') { if ($this->_show_databases_disabled) { return array(); } if (! empty($like_db_name)) { $like = " LIKE '" . $like_db_name . "';"; } else { $like = ";"; } $database_list = PMA_DBI_fetch_result('SHOW DATABASES' . $like, 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('SHOW DATABASES' . $like, 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::$_need_to_reindex * @uses PMA_List_Database::_checkOnlyDatabase() * @uses PMA_List_Database::_retrieve() * @uses PMA_List_Database::_checkHideDatabase() * @uses PMA_List_Database::_checkAccess() * @uses PMA_MYSQL_INT_VERSION * @uses array_values() * @uses natsort() * @global array $cfg */ function build() { $this->items = array(); if (! $this->_checkOnlyDatabase()) { $this->items = $this->_retrieve(); if ($GLOBALS['cfg']['NaturalOrder']) { natsort($this->items); $this->_need_to_reindex = true; } } $this->_checkHideDatabase(); // 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) { $this->_checkAccess(); } if ($this->_need_to_reindex) { $this->items = array_values($this->items); } } /** * 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() * @global array $cfg * @return boolean false if there is no only_db, otherwise true */ 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; } 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 $this->items = array_merge($this->items, array_diff($this->_retrieve(), $this->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 $this->items[] = PMA_unescape_mysql_wildcards($each_only_db); continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -