2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * holds the PMA_List_Database class
9 if (! defined('PHPMYADMIN')) {
16 require_once './libraries/List.class.php';
17 require_once './libraries/check_user_privileges.lib.php';
20 * handles database lists
23 * $PMA_List_Database = new PMA_List_Database($userlink);
26 * @todo this object should be attached to the PMA_Server object
29 * @since phpMyAdmin 2.9.10
31 class PMA_List_Database
extends PMA_List
34 * @var mixed database link resource|object to be used
37 protected $db_link = null;
40 * @var mixed user database link resource|object
43 protected $db_link_user = null;
48 * @param mixed $db_link_user user database link resource|object
50 public function __construct($db_link_user = null)
52 $this->db_link
= $db_link_user;
53 $this->db_link_user
= $db_link_user;
55 parent
::__construct();
60 * checks if the configuration wants to hide some databases
64 protected function checkHideDatabase()
66 if (empty($GLOBALS['cfg']['Server']['hide_db'])) {
70 foreach ($this->getArrayCopy() as $key => $db) {
71 if (preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db)) {
72 $this->offsetUnset($key);
78 * retrieves database list from server
80 * @param string $like_db_name usually a db_name containing wildcards
84 protected function retrieve($like_db_name = null)
86 $database_list = array();
88 if (! $GLOBALS['cfg']['Server']['DisableIS']) {
89 $command .= "SELECT `SCHEMA_NAME` FROM `INFORMATION_SCHEMA`.`SCHEMATA`";
90 if (null !== $like_db_name) {
91 $command .= " WHERE `SCHEMA_NAME` LIKE '" . $like_db_name . "'";
94 if ($GLOBALS['dbs_to_test'] === false ||
null !== $like_db_name) {
95 $command .= "SHOW DATABASES";
96 if (null !== $like_db_name) {
97 $command .= " LIKE '" . $like_db_name . "'";
100 foreach ($GLOBALS['dbs_to_test'] as $db) {
101 $database_list = array_merge(
102 $database_list, $this->retrieve($db)
109 $database_list = $GLOBALS['dbi']->fetchResult(
110 $command, null, null, $this->db_link
114 if ($GLOBALS['cfg']['NaturalOrder']) {
115 natsort($database_list);
117 // need to sort anyway, otherwise information_schema
119 sort($database_list);
122 return $database_list;
130 public function build()
132 if (! $this->checkOnlyDatabase()) {
133 $items = $this->retrieve();
134 $this->exchangeArray($items);
137 $this->checkHideDatabase();
141 * checks the only_db configuration
143 * @return boolean false if there is no only_db, otherwise true
145 protected function checkOnlyDatabase()
147 if (is_string($GLOBALS['cfg']['Server']['only_db'])
148 && /*overload*/mb_strlen($GLOBALS['cfg']['Server']['only_db'])
150 $GLOBALS['cfg']['Server']['only_db'] = array(
151 $GLOBALS['cfg']['Server']['only_db']
155 if (! is_array($GLOBALS['cfg']['Server']['only_db'])) {
161 foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) {
163 // check if the db name contains wildcard,
164 // thus containing not escaped _ or %
165 if (! preg_match('/(^|[^\\\\])(_|%)/', $each_only_db)) {
166 // ... not contains wildcard
167 $items[] = PMA_Util
::unescapeMysqlWildcards($each_only_db);
171 $items = array_merge($items, $this->retrieve($each_only_db));
174 $this->exchangeArray($items);
180 * returns default item
182 * @return string default item
184 public function getDefault()
186 if (/*overload*/mb_strlen($GLOBALS['db'])) {
187 return $GLOBALS['db'];
190 return $this->getEmpty();