PMA_DBI_get_dblist

This commit is contained in:
Marc Delisle
2004-01-19 20:09:43 +00:00
parent 309aeabd9c
commit 02e945b376
3 changed files with 38 additions and 39 deletions

View File

@@ -5,6 +5,10 @@ phpMyAdmin - Changelog
$Id$ $Id$
$Source$ $Source$
2004-01-19 Marc Delisle <lem9@users.sourceforge.net>
* libraries/common.lib.php, libraries/dbi/mysql.dbi.lib.php:
PMA_DBI_get_dblist()
2004-01-17 Michal Cihar <argh@cihar.com> 2004-01-17 Michal Cihar <argh@cihar.com>
* lang/czech: Updated. * lang/czech: Updated.

View File

@@ -571,32 +571,14 @@ if ($is_minimum_common == FALSE) {
* @access private * @access private
*/ */
function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist) { function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist) {
if ($only_db_check == FALSE) { if ($only_db_check == FALSE) {
// ... first checks whether the "safe_show_database" is on or not // try to get the available dbs list
// (if MYSQL supports this) // use userlink by default
$is_safe_show_dbs = FALSE; $dblist = PMA_DBI_get_dblist();
if (PMA_MYSQL_INT_VERSION >= 40002) { $dblist_cnt = count($dblist);
$is_safe_show_dbs = 'ON';
}
else {
$local_query = 'SHOW VARIABLES LIKE \'safe\\_show\\_database\'';
$rs = PMA_mysql_query($local_query, $dbh); // Debug: or PMA_mysqlDie('', $local_query, FALSE);
$is_safe_show_dbs = ($rs) ? @PMA_mysql_result($rs, 0, 'Value') : FALSE;
mysql_free_result($rs);
}
// ... and if on, try to get the available dbs list // did not work so check for available databases in the "mysql" db;
if ($is_safe_show_dbs && strtoupper($is_safe_show_dbs) != 'OFF') { // I don't think we can fall here now...
$uva_alldbs = mysql_list_dbs($userlink);
while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
$dblist[] = $uva_row[0];
} // end while
$dblist_cnt = count($dblist);
unset($uva_alldbs);
} // end if ($is_safe_show_dbs)
// ... else checks for available databases in the "mysql" db
if (!$dblist_cnt) { if (!$dblist_cnt) {
$auth_query = 'SELECT User, Select_priv ' $auth_query = 'SELECT User, Select_priv '
. 'FROM mysql.user ' . 'FROM mysql.user '
@@ -650,7 +632,7 @@ function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cf
} }
} // end while } // end while
mysql_free_result($rs); mysql_free_result($rs);
$uva_alldbs = mysql_list_dbs($dbh); $uva_alldbs = mysql_list_dbs($GLOBALS['dbh']);
// loic1: all databases cases - part 2 // loic1: all databases cases - part 2
if (isset($uva_mydbs['%'])) { if (isset($uva_mydbs['%'])) {
while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) { while ($uva_row = PMA_mysql_fetch_array($uva_alldbs)) {
@@ -1142,19 +1124,8 @@ if ($is_minimum_common == FALSE) {
// 2. Allowed database list is empty -> gets the list of all databases // 2. Allowed database list is empty -> gets the list of all databases
// on the server // on the server
else { else {
$dbs = mysql_list_dbs() or PMA_mysqlDie('', 'SHOW DATABASES;', FALSE, $error_url); $dblist = PMA_DBI_get_dblist(); // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', FALSE, $error_url);
$num_dbs = ($dbs) ? @mysql_num_rows($dbs) : 0; $num_dbs = count($dblist);
$real_num_dbs = 0;
for ($i = 0; $i < $num_dbs; $i++) {
$db_name_tmp = PMA_mysql_dbname($dbs, $i);
$dblink = @PMA_mysql_select_db($db_name_tmp);
if ($dblink) {
$dblist[] = $db_name_tmp;
$real_num_dbs++;
}
} // end for
mysql_free_result($dbs);
$num_dbs = $real_num_dbs;
} // end else } // end else
return TRUE; return TRUE;

View File

@@ -169,4 +169,28 @@ function PMA_DBI_close($link = '') {
@mysql_close($link); @mysql_close($link);
} }
?> function PMA_DBI_get_dblist($link = '') {
if (empty($link)) {
$link = $GLOBALS['userlink'];
}
$res = PMA_DBI_try_query('SHOW DATABASES;', $link);
$dbs_array = array();
while ($row = PMA_DBI_fetch_row($res)) {
// not sure if we have to convert before the (possible) select_db()
$dbname = PMA_convert_display_charset($row[0]);
// Before MySQL 4.0.2, SHOW DATABASES could send the
// whole list, so check if we really have access:
if (PMA_MYSQL_CLIENT_API < 40002) {
$dblink = @PMA_mysql_select_db($dbname);
if (!dblink) {
continue;
}
}
$dbs_array[] = $dbname;
}
PMA_DBI_free_result($res);
unset($res);
return $dbs_array;
}
?>