2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * holds the ListDatabase class
10 use PhpMyAdmin\ListAbstract
;
13 require_once './libraries/check_user_privileges.inc.php';
16 * handles database lists
19 * $ListDatabase = new ListDatabase();
22 * @todo this object should be attached to the PMA_Server object
25 * @since phpMyAdmin 2.9.10
27 class ListDatabase
extends ListAbstract
32 public function __construct()
34 parent
::__construct();
39 * checks if the configuration wants to hide some databases
43 protected function checkHideDatabase()
45 if (empty($GLOBALS['cfg']['Server']['hide_db'])) {
49 foreach ($this->getArrayCopy() as $key => $db) {
50 if (preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db)) {
51 $this->offsetUnset($key);
57 * retrieves database list from server
59 * @param string $like_db_name usually a db_name containing wildcards
63 protected function retrieve($like_db_name = null)
65 $database_list = array();
67 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
68 $command .= "SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`";
69 if (null !== $like_db_name) {
70 $command .= " WHERE `SCHEMA_NAME` LIKE '" . $like_db_name . "'";
73 if ($GLOBALS['dbs_to_test'] === false ||
null !== $like_db_name) {
74 $command .= "SHOW DATABASES";
75 if (null !== $like_db_name) {
76 $command .= " LIKE '" . $like_db_name . "'";
79 foreach ($GLOBALS['dbs_to_test'] as $db) {
80 $database_list = array_merge(
81 $database_list, $this->retrieve($db)
88 $database_list = $GLOBALS['dbi']->fetchResult(
93 if ($GLOBALS['cfg']['NaturalOrder']) {
94 usort($database_list, 'strnatcasecmp');
96 // need to sort anyway, otherwise information_schema
101 return $database_list;
109 public function build()
111 if (! $this->checkOnlyDatabase()) {
112 $items = $this->retrieve();
113 $this->exchangeArray($items);
116 $this->checkHideDatabase();
120 * checks the only_db configuration
122 * @return boolean false if there is no only_db, otherwise true
124 protected function checkOnlyDatabase()
126 if (is_string($GLOBALS['cfg']['Server']['only_db'])
127 && strlen($GLOBALS['cfg']['Server']['only_db']) > 0
129 $GLOBALS['cfg']['Server']['only_db'] = array(
130 $GLOBALS['cfg']['Server']['only_db']
134 if (! is_array($GLOBALS['cfg']['Server']['only_db'])) {
140 foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) {
142 // check if the db name contains wildcard,
143 // thus containing not escaped _ or %
144 if (! preg_match('/(^|[^\\\\])(_|%)/', $each_only_db)) {
145 // ... not contains wildcard
146 $items[] = Util
::unescapeMysqlWildcards($each_only_db);
150 $items = array_merge($items, $this->retrieve($each_only_db));
153 $this->exchangeArray($items);
159 * returns default item
161 * @return string default item
163 public function getDefault()
165 if (strlen($GLOBALS['db']) > 0) {
166 return $GLOBALS['db'];
169 return $this->getEmpty();