diff options
154 files changed, 3371 insertions, 3329 deletions
diff --git a/db_create.php b/db_create.php index e6fe35a5fc..72138b3b44 100644 --- a/db_create.php +++ b/db_create.php @@ -52,10 +52,10 @@ if (! empty($db_collation)) { } $sql_query .= ';'; -$result = PMA_DBI_tryQuery($sql_query); +$result = $GLOBALS['dbi']->tryQuery($sql_query); if (! $result) { - $message = PMA_Message::rawError(PMA_DBI_getError()); + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); // avoid displaying the not-created db name in header or navi panel $GLOBALS['db'] = ''; $GLOBALS['table'] = ''; @@ -91,7 +91,7 @@ if (! $result) { */ $db_url_params['db'] = $new_db; - $is_superuser = PMA_isSuperuser(); + $is_superuser = $GLOBALS['dbi']->isSuperuser(); $column_order = PMA_getColumnOrder(); $url_query = PMA_generate_common_url($new_db); diff --git a/db_datadict.php b/db_datadict.php index 8bc7983622..7278c576c7 100644 --- a/db_datadict.php +++ b/db_datadict.php @@ -57,8 +57,8 @@ if ($cfgRelation['commwork']) { /** * Selects the database and gets tables names */ -PMA_DBI_selectDb($db); -$tables = PMA_DBI_getTables($db); +$GLOBALS['dbi']->selectDb($db); +$tables = $GLOBALS['dbi']->getTables($db); $count = 0; foreach ($tables as $table) { @@ -77,8 +77,8 @@ foreach ($tables as $table) { * Gets table keys and retains them */ - PMA_DBI_selectDb($db); - $indexes = PMA_DBI_getTableIndexes($db, $table); + $GLOBALS['dbi']->selectDb($db); + $indexes = $GLOBALS['dbi']->getTableIndexes($db, $table); $primary = ''; $indexes = array(); $lastIndex = ''; @@ -117,7 +117,7 @@ foreach ($tables as $table) { /** * Gets columns properties */ - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); if (PMA_MYSQL_INT_VERSION < 50025) { // We need this to correctly learn if a TIMESTAMP is NOT NULL, since @@ -128,7 +128,7 @@ foreach ($tables as $table) { $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); - $show_create_table = PMA_DBI_fetchValue( + $show_create_table = $GLOBALS['dbi']->fetchValue( $show_create_table_query, 0, 1 ); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); @@ -215,7 +215,7 @@ foreach ($tables as $table) { // contrary. Believe the latter. /** * @todo merge this logic with the one in tbl_structure.php - * or move it in a function similar to PMA_DBI_getColumnsFull() + * or move it in a function similar to $GLOBALS['dbi']->getColumnsFull() * but based on SHOW CREATE TABLE because information_schema * cannot be trusted in this case (MySQL bug) */ diff --git a/db_operations.php b/db_operations.php index 01ade238dd..b0e40a015d 100644 --- a/db_operations.php +++ b/db_operations.php @@ -62,9 +62,9 @@ if (strlen($db) PMA_runProcedureAndFunctionDefinitions($db); // go back to current db, just in case - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); - $tables_full = PMA_DBI_getTablesFull($db); + $tables_full = $GLOBALS['dbi']->getTablesFull($db); include_once "libraries/plugin_interface.lib.php"; // remove all foreign key constraints, otherwise we can get errors @@ -109,7 +109,7 @@ if (strlen($db) } // go back to current db, just in case - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); // Duplicate the bookmarks for this db (done once for each db) PMA_duplicateBookmarks($_error, $db); @@ -124,7 +124,7 @@ if (strlen($db) // if someday the RENAME DATABASE reappears, do not DROP $local_query = 'DROP DATABASE ' . PMA_Util::backquote($db) . ';'; $sql_query .= "\n" . $local_query; - PMA_DBI_query($local_query); + $GLOBALS['dbi']->query($local_query); $message = PMA_Message::success(__('Database %1$s has been renamed to %2$s')); $message->addParam($db); @@ -206,7 +206,7 @@ if (empty($is_info)) { } $_REQUEST['db_collation'] = PMA_getDbCollation($db); -$is_information_schema = PMA_isSystemSchema($db); +$is_information_schema = $GLOBALS['dbi']->isSystemSchema($db); $response->addHTML('<div id="boxContainer" data-box-width="300">'); diff --git a/db_printview.php b/db_printview.php index 4a75313ad1..965ca1af76 100644 --- a/db_printview.php +++ b/db_printview.php @@ -31,7 +31,7 @@ $cfgRelation = PMA_getRelationsParam(); * If there is at least one table, displays the printer friendly view, else * an error message */ -$tables = PMA_DBI_getTablesFull($db); +$tables = $GLOBALS['dbi']->getTablesFull($db); $num_tables = count($tables); echo '<br />'; diff --git a/db_tracking.php b/db_tracking.php index 3bc956a1d7..6d0df6ca28 100644 --- a/db_tracking.php +++ b/db_tracking.php @@ -67,7 +67,7 @@ $all_tables_query = ' SELECT table_name, MAX(version) as version FROM ' . $all_tables_result = PMA_queryAsControlUser($all_tables_query); // If a HEAD version exists -if (PMA_DBI_numRows($all_tables_result) > 0) { +if ($GLOBALS['dbi']->numRows($all_tables_result) > 0) { ?> <div id="tracked_tables"> <h3><?php echo __('Tracked tables');?></h3> @@ -104,7 +104,7 @@ if (PMA_DBI_numRows($all_tables_result) > 0) { } $style = 'odd'; - while ($one_result = PMA_DBI_fetchArray($all_tables_result)) { + while ($one_result = $GLOBALS['dbi']->fetchArray($all_tables_result)) { list($table_name, $version_number) = $one_result; $table_query = ' SELECT * FROM ' . PMA_Util::backquote($GLOBALS['cfg']['Server']['pmadb']) . '.' . @@ -114,7 +114,7 @@ if (PMA_DBI_numRows($all_tables_result) > 0) { . '\' AND `version` = \'' . $version_number . '\''; $table_result = PMA_queryAsControlUser($table_query); - $version_data = PMA_DBI_fetchArray($table_result); + $version_data = $GLOBALS['dbi']->fetchArray($table_result); if ($version_data['tracking_active'] == 1) { $version_status = __('active'); diff --git a/export.php b/export.php index 0bedb6b97d..21c188ffbd 100644 --- a/export.php +++ b/export.php @@ -649,7 +649,7 @@ do { $export_plugin->exportRoutines($current_db); } - $tables = PMA_DBI_getTables($current_db); + $tables = $GLOBALS['dbi']->getTables($current_db); $views = array(); foreach ($tables as $table) { // if this is a view, collect it for later; @@ -836,7 +836,7 @@ do { $sql_query = preg_replace('%;\s*$%', '', $sql_query); } $local_query = $sql_query . $add_query; - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); } else { $local_query = 'SELECT * FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . $add_query; diff --git a/import.php b/import.php index b877414436..3c98ea3486 100644 --- a/import.php +++ b/import.php @@ -182,7 +182,7 @@ if ($import_type == 'table') { if (strlen($db)) { - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); } @set_time_limit($cfg['ExecTimeLimit']); @@ -447,7 +447,7 @@ if ($GLOBALS['PMA_recoding_engine'] != PMA_CHARSET_NONE && isset($charset_of_fil __('Cannot convert file\'s character set without character set conversion library') ); } else { - PMA_DBI_query('SET NAMES \'' . $charset_of_file . '\''); + $GLOBALS['dbi']->query('SET NAMES \'' . $charset_of_file . '\''); // We can not show query in this case, it is in different charset $sql_query_disabled = true; $reset_charset = true; @@ -501,8 +501,8 @@ if ($file_to_unlink != '') { // Reset charset back, if we did some changes if ($reset_charset) { - PMA_DBI_query('SET CHARACTER SET utf8'); - PMA_DBI_query( + $GLOBALS['dbi']->query('SET CHARACTER SET utf8'); + $GLOBALS['dbi']->query( 'SET SESSION collation_connection =\'' . $collation_connection . '\'' ); } @@ -93,12 +93,12 @@ if ($server > 0) { } } if ($GLOBALS['cfg']['ShowServerInfo'] || empty($cfg['Server']['verbose'])) { - $server_info .= PMA_DBI_getHostInfo(); + $server_info .= $GLOBALS['dbi']->getHostInfo(); } if (! empty($cfg['Server']['verbose']) && $GLOBALS['cfg']['ShowServerInfo']) { $server_info .= ')'; } - $mysql_cur_user_and_host = PMA_DBI_fetchValue('SELECT USER();'); + $mysql_cur_user_and_host = $GLOBALS['dbi']->fetchValue('SELECT USER();'); // should we add the port info here? $short_server_info = (!empty($GLOBALS['cfg']['Server']['verbose']) @@ -246,7 +246,7 @@ if ($server > 0 && $GLOBALS['cfg']['ShowServerInfo']) { 'li_server_version' ); PMA_printListItem( - __('Protocol version:') . ' ' . PMA_DBI_getProtoInfo(), + __('Protocol version:') . ' ' . $GLOBALS['dbi']->getProtoInfo(), 'li_mysql_proto' ); PMA_printListItem( @@ -273,7 +273,7 @@ if ($GLOBALS['cfg']['ShowServerInfo'] || $GLOBALS['cfg']['ShowPhpInfo']) { PMA_printListItem($_SERVER['SERVER_SOFTWARE'], 'li_web_server_software'); if ($server > 0) { - $client_version_str = PMA_DBI_getClientInfo(); + $client_version_str = $GLOBALS['dbi']->getClientInfo(); if (preg_match('#\d+\.\d+\.\d+#', $client_version_str) && in_array($GLOBALS['cfg']['Server']['extension'], array('mysql', 'mysqli')) ) { @@ -502,12 +502,12 @@ if ($server > 0) { * (a difference on the third digit does not count). * If someday there is a constant that we can check about mysqlnd, * we can use it instead of strpos(). - * If no default server is set, PMA_DBI_getClientInfo() is not defined yet. + * If no default server is set, $GLOBALS['dbi']->getClientInfo() is not defined yet. * Drizzle can speak MySQL protocol, so don't warn about version mismatch for * Drizzle servers. */ if (function_exists('PMA_DBI_getClientInfo') && !PMA_DRIZZLE) { - $_client_info = PMA_DBI_getClientInfo(); + $_client_info = $GLOBALS['dbi']->getClientInfo(); if ($server > 0 && strpos($_client_info, 'mysqlnd') === false && substr(PMA_MYSQL_CLIENT_API, 0, 3) != substr(PMA_MYSQL_INT_VERSION, 0, 3) diff --git a/libraries/Advisor.class.php b/libraries/Advisor.class.php index 73c32b326a..529a454d6c 100644 --- a/libraries/Advisor.class.php +++ b/libraries/Advisor.class.php @@ -32,13 +32,13 @@ class Advisor // Step 1: Get some variables to evaluate on $this->variables = array_merge( - PMA_DBI_fetchResult('SHOW GLOBAL STATUS', 0, 1), - PMA_DBI_fetchResult('SHOW GLOBAL VARIABLES', 0, 1) + $GLOBALS['dbi']->fetchResult('SHOW GLOBAL STATUS', 0, 1), + $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES', 0, 1) ); if (PMA_DRIZZLE) { $this->variables = array_merge( $this->variables, - PMA_DBI_fetchResult( + $GLOBALS['dbi']->fetchResult( "SELECT concat('Com_', variable_name), variable_value FROM data_dictionary.GLOBAL_STATEMENTS", 0, 1 ) diff --git a/libraries/DBQbe.class.php b/libraries/DBQbe.class.php index 051b8c5ce2..bd382d9fb9 100644 --- a/libraries/DBQbe.class.php +++ b/libraries/DBQbe.class.php @@ -258,19 +258,19 @@ class PMA_DbQbe $this->_criteriaTables[$each_table] = ' selected="selected"'; } } // end if - $all_tables = PMA_DBI_query( + $all_tables = $GLOBALS['dbi']->query( 'SHOW TABLES FROM ' . PMA_Util::backquote($this->_db) . ';', null, PMA_DBI_QUERY_STORE ); - $all_tables_count = PMA_DBI_numRows($all_tables); + $all_tables_count = $GLOBALS['dbi']->numRows($all_tables); if (0 == $all_tables_count) { PMA_Message::error(__('No tables found in database.'))->display(); exit; } // The tables list gets from MySQL - while (list($table) = PMA_DBI_fetchRow($all_tables)) { - $columns = PMA_DBI_getColumns($this->_db, $table); + while (list($table) = $GLOBALS['dbi']->fetchRow($all_tables)) { + $columns = $GLOBALS['dbi']->getColumns($this->_db, $table); if (empty($this->_criteriaTables[$table]) && ! empty($_REQUEST['TableList']) @@ -296,7 +296,7 @@ class PMA_DbQbe } // end foreach } // end if } // end while - PMA_DBI_freeResult($all_tables); + $GLOBALS['dbi']->freeResult($all_tables); // sets the largest width found $this->_realwidth = $this->_form_column_width . 'ex'; @@ -1026,7 +1026,7 @@ class PMA_DbQbe $index_columns = array(); foreach ($all_tables as $table) { - $indexes = PMA_DBI_getTableIndexes($this->_db, $table); + $indexes = $GLOBALS['dbi']->getTableIndexes($this->_db, $table); foreach ($indexes as $index) { $column = $table . '.' . $index['Column_name']; if (isset($all_columns[$column])) { @@ -1065,7 +1065,7 @@ class PMA_DbQbe private function _getLeftJoinColumnCandidates($all_tables, $all_columns, $where_clause_columns ) { - PMA_DBI_selectDb($this->_db); + $GLOBALS['dbi']->selectDb($this->_db); $candidate_columns = array(); // Get unique columns and index columns diff --git a/libraries/DatabaseInterface.class.php b/libraries/DatabaseInterface.class.php new file mode 100644 index 0000000000..0e17fe5a15 --- /dev/null +++ b/libraries/DatabaseInterface.class.php @@ -0,0 +1,2431 @@ +<?php +/* vim: set expandtab sw=4 ts=4 sts=4: */ +/** + * Common Option Constants For DBI Functions + * + * @package PhpMyAdmin-DBI + */ +if (! defined('PHPMYADMIN')) { + exit; +} + +/** + * Force STORE_RESULT method, ignored by classic MySQL. + */ +define('PMA_DBI_QUERY_STORE', 1); +/** + * Do not read whole query. + */ +define('PMA_DBI_QUERY_UNBUFFERED', 2); +/** + * Get session variable. + */ +define('PMA_DBI_GETVAR_SESSION', 1); +/** + * Get global variable. + */ +define('PMA_DBI_GETVAR_GLOBAL', 2); + +/** + * Checks whether database extension is loaded + * + * @param string $extension mysql extension to check + * + * @return bool + */ +function PMA_DBI_checkDbExtension($extension = 'mysql') +{ + if ($extension == 'drizzle' && function_exists('drizzle_create')) { + return true; + } else if (function_exists($extension . '_connect')) { + return true; + } + + return false; +} + +$extension = null; +if (defined('TESTSUITE')) { + /** + * For testsuite we use dummy driver which can fake some queries. + */ + include_once './libraries/dbi/DBIDummy.class.php'; + $extension = new PMA_DBI_Dummy(); +} else { + + /** + * check for requested extension + */ + if (! PMA_DBI_checkDbExtension($GLOBALS['cfg']['Server']['extension'])) { + + // if it fails try alternative extension ... + // and display an error ... + + /** + * @todo add different messages for alternative extension + * and complete fail (no alternative extension too) + */ + PMA_warnMissingExtension( + $GLOBALS['cfg']['Server']['extension'], + false, + PMA_Util::showDocu('faq', 'faqmysql') + ); + + if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') { + $alternativ_extension = 'mysqli'; + } else { + $alternativ_extension = 'mysql'; + } + + if (! PMA_DBI_checkDbExtension($alternativ_extension)) { + // if alternative fails too ... + PMA_warnMissingExtension( + $GLOBALS['cfg']['Server']['extension'], + true, + PMA_Util::showDocu('faq', 'faqmysql') + ); + } + + $GLOBALS['cfg']['Server']['extension'] = $alternativ_extension; + unset($alternativ_extension); + } + + /** + * Including The DBI Plugin + */ + switch($GLOBALS['cfg']['Server']['extension']) { + case 'mysql' : + include_once './libraries/dbi/DBIMysql.class.php'; + $extension = new PMA_DBI_Mysql(); + break; + case 'mysqli' : + include_once './libraries/dbi/DBIMysqli.class.php'; + $extension = new PMA_DBI_Mysqli(); + break; + case 'drizzle' : + include_once './libraries/dbi/DBIDrizzle.class.php'; + $extension = new PMA_DBI_Drizzle(); + break; + } +} +$GLOBALS['dbi'] = new PMA_DatabaseInterface($extension); + +/** + * usort comparison callback + * + * @param string $a first argument to sort + * @param string $b second argument to sort + * + * @return integer a value representing whether $a should be before $b in the + * sorted array or not + * + * @access private + */ +function PMA_usortComparisonCallback($a, $b) +{ + if ($GLOBALS['cfg']['NaturalOrder']) { + $sorter = 'strnatcasecmp'; + } else { + $sorter = 'strcasecmp'; + } + /* No sorting when key is not present */ + if (! isset($a[$GLOBALS['callback_sort_by']]) + || ! isset($b[$GLOBALS['callback_sort_by']]) + ) { + return 0; + } + // produces f.e.: + // return -1 * strnatcasecmp($a["SCHEMA_TABLES"], $b["SCHEMA_TABLES"]) + return ($GLOBALS['callback_sort_order'] == 'ASC' ? 1 : -1) * $sorter( + $a[$GLOBALS['callback_sort_by']], $b[$GLOBALS['callback_sort_by']] + ); +} // end of the 'PMA_usortComparisonCallback()' function + +/** + * Main interface for database interactions + * + * @package PhpMyAdmin-DBI + */ +class PMA_DatabaseInterface +{ + private $_extension; + + /** + * Constructor + * + * @param object $ext PMA_DBI_Extension object to be used for database queries + */ + public function __construct($ext) + { + $this->_extension = $ext; + } + + /** + * runs a query + * + * @param string $query SQL query to execte + * @param mixed $link optional database link to use + * @param int $options optional query options + * @param bool $cache_affected_rows whether to cache affected rows + * + * @return mixed + */ + public function query($query, $link = null, $options = 0, + $cache_affected_rows = true + ) { + $res = $this->tryQuery($query, $link, $options, $cache_affected_rows) + or PMA_Util::mysqlDie($this->getError($link), $query); + return $res; + } + + /** + * Stores query data into session data for debugging purposes + * + * @param string $query Query text + * @param resource $link database link + * @param resource $result Query result + * @param integer $time Time to execute query + * + * @return void + */ + private function _dbgQuery($query, $link, $result, $time) + { + $hash = md5($query); + + if (isset($_SESSION['debug']['queries'][$hash])) { + $_SESSION['debug']['queries'][$hash]['count']++; + } else { + $_SESSION['debug']['queries'][$hash] = array(); + if ($result == false) { + $_SESSION['debug']['queries'][$hash]['error'] + = '<b style="color:red">' . mysqli_error($link) . '</b>'; + } + $_SESSION['debug']['queries'][$hash]['count'] = 1; + $_SESSION['debug']['queries'][$hash]['query'] = $query; + $_SESSION['debug']['queries'][$hash]['time'] = $time; + } + + $trace = array(); + foreach (debug_backtrace() as $trace_step) { + $trace[] + = (isset($trace_step['file']) + ? PMA_Error::relPath($trace_step['file']) + : '') + . (isset($trace_step['line']) + ? '#' . $trace_step['line'] . ': ' + : '') + . (isset($trace_step['class']) ? $trace_step['class'] : '') + . (isset($trace_step['type']) ? $trace_step['type'] : '') + . (isset($trace_step['function']) ? $trace_step['function'] : '') + . '(' + . (isset($trace_step['params']) + ? implode(', ', $trace_step['params']) + : '' + ) + . ')' + ; + } + $_SESSION['debug']['queries'][$hash]['trace'][] = $trace; + } + + /** + * runs a query and returns the result + * + * @param string $query query to run + * @param resource $link mysql link resource + * @param integer $options query options + * @param bool $cache_affected_rows whether to cache affected row + * + * @return mixed + */ + public function tryQuery($query, $link = null, $options = 0, + $cache_affected_rows = true + ) { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return false; + } + } + + if ($GLOBALS['cfg']['DBG']['sql']) { + $time = microtime(true); + } + + $result = $this->_extension->realQuery($query, $link, $options); + + if ($cache_affected_rows) { + $GLOBALS['cached_affected_rows'] = $this->affectedRows($link, false); + } + + if ($GLOBALS['cfg']['DBG']['sql']) { + $time = microtime(true) - $time; + $this->_dbgQuery($query, $link, $result, $time); + } + if ($result != false && PMA_Tracker::isActive() == true ) { + PMA_Tracker::handleQuery($query); + } + + return $result; + } + + /** + * Run multi query statement and return results + * + * @param string $multi_query multi query statement to execute + * @param mysqli $link mysqli object + * + * @return mysqli_result collection | boolean(false) + */ + public function tryMultiQuery($multi_query = '', $link = null) + { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return false; + } + } + + return $this->_extension->realMultiQuery($link, $multi_query); + } + + /** + * converts charset of a mysql message, usually coming from mysql_error(), + * into PMA charset, usally UTF-8 + * uses language to charset mapping from mysql/share/errmsg.txt + * and charset names to ISO charset from information_schema.CHARACTER_SETS + * + * @param string $message the message + * + * @return string $message + */ + public function convertMessage($message) + { + // latin always last! + $encodings = array( + 'japanese' => 'EUC-JP', //'ujis', + 'japanese-sjis' => 'Shift-JIS', //'sjis', + 'korean' => 'EUC-KR', //'euckr', + 'russian' => 'KOI8-R', //'koi8r', + 'ukrainian' => 'KOI8-U', //'koi8u', + 'greek' => 'ISO-8859-7', //'greek', + 'serbian' => 'CP1250', //'cp1250', + 'estonian' => 'ISO-8859-13', //'latin7', + 'slovak' => 'ISO-8859-2', //'latin2', + 'czech' => 'ISO-8859-2', //'latin2', + 'hungarian' => 'ISO-8859-2', //'latin2', + 'polish' => 'ISO-8859-2', //'latin2', + 'romanian' => 'ISO-8859-2', //'latin2', + 'spanish' => 'CP1252', //'latin1', + 'swedish' => 'CP1252', //'latin1', + 'italian' => 'CP1252', //'latin1', + 'norwegian-ny' => 'CP1252', //'latin1', + 'norwegian' => 'CP1252', //'latin1', + 'portuguese' => 'CP1252', //'latin1', + 'danish' => 'CP1252', //'latin1', + 'dutch' => 'CP1252', //'latin1', + 'english' => 'CP1252', //'latin1', + 'french' => 'CP1252', //'latin1', + 'german' => 'CP1252', //'latin1', + ); + + $server_language = $this->fetchValue( + 'SHOW VARIABLES LIKE \'language\';', + 0, + 1 + ); + if ($server_language) { + $found = array(); + $match = preg_match( + '&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', + $server_language, + $found + ); + if ($match) { + $server_language = $found[1]; + } + } + + if (! empty($server_language) && isset($encodings[$server_language])) { + $encoding = $encodings[$server_language]; + } else { + /* Fallback to CP1252 if we can not detect */ + $encoding = 'CP1252'; + } + + if (function_exists('iconv')) { + if ((@stristr(PHP_OS, 'AIX')) + && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) + && (@strcasecmp(ICONV_VERSION, 'unknown') == 0) + ) { + include_once './libraries/iconv_wrapper.lib.php'; + $message = PMA_aix_iconv_wrapper( + $encoding, + 'utf-8' . $GLOBALS['cfg']['IconvExtraParams'], + $message + ); + } else { + $message = iconv( + $encoding, + 'utf-8' . $GLOBALS['cfg']['IconvExtraParams'], + $message + ); + } + } elseif (function_exists('recode_string')) { + $message = recode_string( + $encoding . '..' . 'utf-8', + $message + ); + } elseif (function_exists('libiconv')) { + $message = libiconv($encoding, 'utf-8', $message); + } elseif (function_exists('mb_convert_encoding')) { + // do not try unsupported charsets + if (! in_array($server_language, array('ukrainian', 'greek', 'serbian'))) { + $message = mb_convert_encoding( + $message, + 'utf-8', + $encoding + ); + } + } + + return $message; + } + + /** + * returns array with table names for given db + * + * @param string $database name of database + * @param mixed $link mysql link resource|object + * + * @return array tables names + */ + public function getTables($database, $link = null) + { + return $this->fetchResult( + 'SHOW TABLES FROM ' . PMA_Util::backquote($database) . ';', + null, + 0, + $link, + PMA_DBI_QUERY_STORE + ); + } + + /** + * returns array of all tables in given db or dbs + * this function expects unquoted names: + * RIGHT: my_database + * WRONG: `my_database` + * WRONG: my\_database + * if $tbl_is_group is true, $table is used as filter for table names + * if $tbl_is_group is 'comment, $table is used as filter for table comments + * + * <code> + * $GLOBALS['dbi']->getTablesFull('my_database'); + * $GLOBALS['dbi']->getTablesFull('my_database', 'my_table')); + * $GLOBALS['dbi']->getTablesFull('my_database', 'my_tables_', true)); + * $GLOBALS['dbi']->getTablesFull('my_database', 'my_tables_', 'comment')); + * </code> + * + * @param string $database database + * @param string|bool $table table or false + * @param boolean|string $tbl_is_group $table is a table group + * @param mixed $link mysql link + * @param integer $limit_offset zero-based offset for the count + * @param boolean|integer $limit_count number of tables to return + * @param string $sort_by table attribute to sort by + * @param string $sort_order direction to sort (ASC or DESC) + * + * @todo move into PMA_Table + * + * @return array list of tables in given db(s) + */ + public function getTablesFull($database, $table = false, + $tbl_is_group = false, $link = null, $limit_offset = 0, + $limit_count = false, $sort_by = 'Name', $sort_order = 'ASC' + ) { + if (true === $limit_count) { + $limit_count = $GLOBALS['cfg']['MaxTableList']; + } + // prepare and check parameters + if (! is_array($database)) { + $databases = array($database); + } else { + $databases = $database; + } + + $tables = array(); + + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + // get table information from information_schema + if ($table) { + if (true === $tbl_is_group) { + $sql_where_table = 'AND t.`TABLE_NAME` LIKE \'' + . PMA_Util::escapeMysqlWildcards( + PMA_Util::sqlAddSlashes($table) + ) + . '%\''; + } elseif ('comment' === $tbl_is_group) { + $sql_where_table = 'AND t.`TABLE_COMMENT` LIKE \'' + . PMA_Util::escapeMysqlWildcards( + PMA_Util::sqlAddSlashes($table) + ) + . '%\''; + } else { + $sql_where_table = 'AND t.`TABLE_NAME` = \'' + . PMA_Util::sqlAddSlashes($table) . '\''; + } + } else { + $sql_where_table = ''; + } + + // for PMA bc: + // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME` + // + // on non-Windows servers, + // added BINARY in the WHERE clause to force a case sensitive + // comparison (if we are looking for the db Aa we don't want + // to find the db aa) + $this_databases = array_map('PMA_Util::sqlAddSlashes', $databases); + + if (PMA_DRIZZLE) { + $engine_info = PMA_Util::cacheGet('drizzle_engines', true); + $stats_join = "LEFT JOIN (SELECT 0 NUM_ROWS) AS stat ON false"; + if (isset($engine_info['InnoDB']) + && $engine_info['InnoDB']['module_library'] == 'innobase' + ) { + $stats_join = "LEFT JOIN data_dictionary.INNODB_SYS_TABLESTATS" + . " stat ON (t.ENGINE = 'InnoDB' AND stat.NAME" + . " = (t.TABLE_SCHEMA || '/') || t.TABLE_NAME)"; + } + + // data_dictionary.table_cache may not contain any data + // for some tables, it's just a table cache + // auto_increment == 0 is cast to NULL because currently + // (2011.03.13 GA) + // Drizzle doesn't provide correct value + $sql = " + SELECT t.*, + t.TABLE_SCHEMA AS `Db`, + t.TABLE_NAME AS `Name`, + t.TABLE_TYPE AS `TABLE_TYPE`, + t.ENGINE AS `Engine`, + t.ENGINE AS `Type`, + t.TABLE_VERSION AS `Version`,-- VERSION + t.ROW_FORMAT AS `Row_format`, + coalesce(tc.ROWS, stat.NUM_ROWS) + AS `Rows`,-- TABLE_ROWS, + coalesce(tc.ROWS, stat.NUM_ROWS) + AS `TABLE_ROWS`, + tc.AVG_ROW_LENGTH AS `Avg_row_length`, -- AVG_ROW_LENGTH + tc.TABLE_SIZE AS `Data_length`, -- DATA_LENGTH + NULL AS `Max_data_length`, -- MAX_DATA_LENGTH + NULL AS `Index_length`, -- INDEX_LENGTH + NULL AS `Data_free`, -- DATA_FREE + nullif(t.AUTO_INCREMENT, 0) + AS `Auto_increment`, + t.TABLE_CREATION_TIME AS `Create_time`, -- CREATE_TIME + t.TABLE_UPDATE_TIME AS `Update_time`, -- UPDATE_TIME + NULL AS `Check_time`, -- CHECK_TIME + t.TABLE_COLLATION AS `Collation`, + NULL AS `Checksum`, -- CHECKSUM + NULL AS `Create_options`, -- CREATE_OPTIONS + t.TABLE_COMMENT AS `Comment` + FROM data_dictionary.TABLES t + LEFT JOIN data_dictionary.TABLE_CACHE tc + ON tc.TABLE_SCHEMA = t.TABLE_SCHEMA AND tc.TABLE_NAME + = t.TABLE_NAME + $stats_join + WHERE t.TABLE_SCHEMA IN ('" . implode("', '", $this_databases) . "') + " . $sql_where_table; + } else { + $sql = ' + SELECT *, + `TABLE_SCHEMA` AS `Db`, + `TABLE_NAME` AS `Name`, + `TABLE_TYPE` AS `TABLE_TYPE`, + `ENGINE` AS `Engine`, + `ENGINE` AS `Type`, + `VERSION` AS `Version`, + `ROW_FORMAT` AS `Row_format`, + `TABLE_ROWS` AS `Rows`, + `AVG_ROW_LENGTH` AS `Avg_row_length`, + `DATA_LENGTH` AS `Data_length`, + `MAX_DATA_LENGTH` AS `Max_data_length`, + `INDEX_LENGTH` AS `Index_length`, + `DATA_FREE` AS `Data_free`, + `AUTO_INCREMENT` AS `Auto_increment`, + `CREATE_TIME` AS `Create_time`, + `UPDATE_TIME` AS `Update_time`, + `CHECK_TIME` AS `Check_time`, + `TABLE_COLLATION` AS `Collation`, + `CHECKSUM` AS `Checksum`, + `CREATE_OPTIONS` AS `Create_options`, + `TABLE_COMMENT` AS `Comment` + FROM `information_schema`.`TABLES` t + WHERE ' . (PMA_IS_WINDOWS ? '' : 'BINARY') . ' `TABLE_SCHEMA` + IN (\'' . implode("', '", $this_databases) . '\') + ' . $sql_where_table; + } + + // Sort the tables + $sql .= " ORDER BY $sort_by $sort_order"; + + if ($limit_count) { + $sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset; + } + + $tables = $this->fetchResult( + $sql, array('TABLE_SCHEMA', 'TABLE_NAME'), null, $link + ); + unset($sql_where_table, $sql); + + if (PMA_DRIZZLE) { + // correct I_S and D_D names returned by D_D.TABLES - + // Drizzle generally uses lower case for them, + // but TABLES returns uppercase + foreach ((array)$database as $db) { + $db_upper = strtoupper($db); + if (!isset($tables[$db]) && isset($tables[$db_upper])) { + $tables[$db] = $tables[$db_upper]; + unset($tables[$db_upper]); + } + } + } + + if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) { + // here, the array's first key is by schema name + foreach ($tables as $one_database_name => $one_database_tables) { + uksort($one_database_tables, 'strnatcasecmp'); + + if ($sort_order == 'DESC') { + $one_database_tables = array_reverse($one_database_tables); + } + $tables[$one_database_name] = $one_database_tables; + } + } + } // end (get information from table schema) + + // If permissions are wrong on even one database directory, + // information_schema does not return any table info for any database + // this is why we fall back to SHOW TABLE STATUS even for MySQL >= 50002 + if (empty($tables) && !PMA_DRIZZLE) { + foreach ($databases as $each_database) { + if ($table || (true === $tbl_is_group)) { + $sql = 'SHOW TABLE STATUS FROM ' + . PMA_Util::backquote($each_database) + .' LIKE \'' + . PMA_Util::escapeMysqlWildcards( + PMA_Util::sqlAddSlashes($table, true) + ) + . '%\''; + } else { + $sql = 'SHOW TABLE STATUS FROM ' + . PMA_Util::backquote($each_database); + } + + $useStatusCache = false; + + if (extension_loaded('apc') + && isset($GLOBALS['cfg']['Server']['StatusCacheDatabases']) + && ! empty($GLOBALS['cfg']['Server']['StatusCacheLifetime']) + ) { + $statusCacheDatabases + = (array) $GLOBALS['cfg']['Server']['StatusCacheDatabases']; + if (in_array($each_database, $statusCacheDatabases)) { + $useStatusCache = true; + } + } + + $each_tables = null; + + if ($useStatusCache) { + $cacheKey = 'phpMyAdmin_tableStatus_' + . sha1($GLOBALS['cfg']['Server']['host'] . '_' . $sql); + + $each_tables = apc_fetch($cacheKey); + } + + if (! $each_tables) { + $each_tables = $this->fetchResult($sql, 'Name', null, $link); + } + + if ($useStatusCache) { + apc_store( + $cacheKey, $each_tables, + $GLOBALS['cfg']['Server']['StatusCacheLifetime'] + ); + } + + // Sort naturally if the config allows it and we're sorting + // the Name column. + if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) { + uksort($each_tables, 'strnatcasecmp'); + + if ($sort_order == 'DESC') { + $each_tables = array_reverse($each_tables); + } + } else { + // Prepare to sort by creating array of the selected sort + // value to pass to array_multisort + + // Size = Data_length + Index_length + if ($sort_by == 'Data_length') { + foreach ($each_tables as $table_name => $table_data) { + ${$sort_by}[$table_name] = strtolower( + $table_data['Data_length'] + $table_data['Index_length'] + ); + } + } else { + foreach ($each_tables as $table_name => $table_data) { + ${$sort_by}[$table_name] + = strtolower($table_data[$sort_by]); + } + } + + if ($sort_order == 'DESC') { + array_multisort($$sort_by, SORT_DESC, $each_tables); + } else { + array_multisort($$sort_by, SORT_ASC, $each_tables); + } + + // cleanup the temporary sort array + unset($$sort_by); + } + + if ($limit_count) { + $each_tables = array_slice( + $each_tables, $limit_offset, $limit_count + ); + } + + foreach ($each_tables as $table_name => $each_table) { + if ('comment' === $tbl_is_group + && 0 === strpos($each_table['Comment'], $table) + ) { + // remove table from list + unset($each_tables[$table_name]); + continue; + } + + if (! isset($each_tables[$table_name]['Type']) + && isset($each_tables[$table_name]['Engine']) + ) { + // pma BC, same parts of PMA still uses 'Type' + $each_tables[$table_name]['Type'] + =& $each_tables[$table_name]['Engine']; + } elseif (! isset($each_tables[$table_name]['Engine']) + && isset($each_tables[$table_name]['Type'])) { + // old MySQL reports Type, newer MySQL reports Engine + $each_tables[$table_name]['Engine'] + =& $each_tables[$table_name]['Type']; + } + + // MySQL forward compatibility + // so pma could use this array as if every server + // is of version >5.0 + // todo : remove and check usage in the rest of the code, + // MySQL 5.0 is required by current PMA version + $each_tables[$table_name]['TABLE_SCHEMA'] + = $each_database; + $each_tables[$table_name]['TABLE_NAME'] + =& $each_tables[$table_name]['Name']; + $each_tables[$table_name]['ENGINE'] + =& $each_tables[$table_name]['Engine']; + $each_tables[$table_name]['VERSION'] + =& $each_tables[$table_name]['Version']; + $each_tables[$table_name]['ROW_FORMAT'] + =& $each_tables[$table_name]['Row_format']; + $each_tables[$table_name]['TABLE_ROWS'] + =& $each_tables[$table_name]['Rows']; + $each_tables[$table_name]['AVG_ROW_LENGTH'] + =& $each_tables[$table_name]['Avg_row_length']; + $each_tables[$table_name]['DATA_LENGTH'] + =& $each_tables[$table_name]['Data_length']; + $each_tables[$table_name]['MAX_DATA_LENGTH'] + =& $each_tables[$table_name]['Max_data_length']; + $each_tables[$table_name]['INDEX_LENGTH'] + =& $each_tables[$table_name]['Index_length']; + $each_tables[$table_name]['DATA_FREE'] + =& $each_tables[$table_name]['Data_free']; + $each_tables[$table_name]['AUTO_INCREMENT'] + =& $each_tables[$table_name]['Auto_increment']; + $each_tables[$table_name]['CREATE_TIME'] + =& $each_tables[$table_name]['Create_time']; + $each_tables[$table_name]['UPDATE_TIME'] + =& $each_tables[$table_name]['Update_time']; + $each_tables[$table_name]['CHECK_TIME'] + =& $each_tables[$table_name]['Check_time']; + $each_tables[$table_name]['TABLE_COLLATION'] + =& $each_tables[$table_name]['Collation']; + $each_tables[$table_name]['CHECKSUM'] + =& $each_tables[$table_name]['Checksum']; + $each_tables[$table_name]['CREATE_OPTIONS'] + =& $each_tables[$table_name]['Create_options']; + $each_tables[$table_name]['TABLE_COMMENT'] + =& $each_tables[$table_name]['Comment']; + + if (strtoupper($each_tables[$table_name]['Comment']) === 'VIEW' + && $each_tables[$table_name]['Engine'] == null + ) { + $each_tables[$table_name]['TABLE_TYPE'] = 'VIEW'; + } else { + /** + * @todo difference between 'TEMPORARY' and 'BASE TABLE' + * but how to detect? + */ + $each_tables[$table_name]['TABLE_TYPE'] = 'BASE TABLE'; + } + } + + $tables[$each_database] = $each_tables; + } + } + + // cache table data + // so PMA_Table does not require to issue SHOW TABLE STATUS again + // Note: I don't see why we would need array_merge_recursive() here, + // as it creates double entries for the same table (for example a double + // entry for Comment when changing the storage engine in Operations) + // Note 2: Instead of array_merge(), simply use the + operator because + // array_merge() renumbers numeric keys starting with 0, therefore + // we would lose a db name thats consists only of numbers + foreach ($tables as $one_database => $its_tables) { + if (isset(PMA_Table::$cache[$one_database])) { + PMA_Table::$cache[$one_database] + = PMA_Table::$cache[$one_database] + $tables[$one_database]; + } else { + PMA_Table::$cache[$one_database] = $tables[$one_database]; + } + } + unset($one_database, $its_tables); + + if (! is_array($database)) { + if (isset($tables[$database])) { + return $tables[$database]; + } elseif (isset($tables[strtolower($database)])) { + // on windows with lower_case_table_names = 1 + // MySQL returns + // with SHOW DATABASES or information_schema.SCHEMATA: `Test` + // but information_schema.TABLES gives `test` + // bug #2036 + // https://sourceforge.net/p/phpmyadmin/bugs/2036/ + return $tables[strtolower($database)]; + } else { + // one database but inexact letter case match + // as Drizzle is always case insensitive, + // we can safely return the only result + if (PMA_DRIZZLE && count($tables) == 1) { + $keys = array_keys($tables); + if (strlen(array_pop($keys)) == strlen($database)) { + return array_pop($tables); + } + } + return $tables; + } + } else { + return $tables; + } + } + + /** + * Get VIEWs in a particular database + * + * @param string $db Database name to look in + * + * @return array $views Set of VIEWs inside the database + */ + public function getVirtualTables($db) + { + + $tables_full = $this->getTablesFull($db); + $views = array(); + + foreach ($tables_full as $table=>$tmp) { + + if (PMA_Table::isView($db, $table)) { + $views[] = $table; + } + + } + + return $views; + + } + + + /** + * returns array with databases containing extended infos about them + * + * @param string $database database + * @param boolean $force_stats retrieve stats also for MySQL < 5 + * @param resource $link mysql link + * @param string $sort_by column to order by + * @param string $sort_order ASC or DESC + * @param integer $limit_offset starting offset for LIMIT + * @param bool|int $limit_count row count for LIMIT or true + * for $GLOBALS['cfg']['MaxDbList'] + * + * @todo move into PMA_List_Database? + * + * @return array $databases + */ + public function getDatabasesFull($database = null, $force_stats = false, + $link = null, $sort_by = 'SCHEMA_NAME', $sort_order = 'ASC', + $limit_offset = 0, $limit_count = false + ) { + $sort_order = strtoupper($sort_order); + + if (true === $limit_count) { + $limit_count = $GLOBALS['cfg']['MaxDbList']; + } + + // initialize to avoid errors when there are no databases + $databases = array(); + + $apply_limit_and_order_manual = true; + + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + /** + * if $GLOBALS['cfg']['NaturalOrder'] is enabled, we cannot use LIMIT + * cause MySQL does not support natural ordering, + * we have to do it afterward + */ + $limit = ''; + if (! $GLOBALS['cfg']['NaturalOrder']) { + if ($limit_count) { + $limit = ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset; + } + + $apply_limit_and_order_manual = false; + } + + // get table information from information_schema + if ($database) { + $sql_where_schema = 'WHERE `SCHEMA_NAME` LIKE \'' + . PMA_Util::sqlAddSlashes($database) . '\''; + } else { + $sql_where_schema = ''; + } + + if (PMA_DRIZZLE) { + // data_dictionary.table_cache may not contain any data for some + // tables, it's just a table cache + $sql = 'SELECT + s.SCHEMA_NAME, + s.DEFAULT_COLLATION_NAME'; + if ($force_stats) { + // no TABLE_CACHE data, stable results are better than + // constantly changing + $sql .= ', + COUNT(t.TABLE_SCHEMA) AS SCHEMA_TABLES, + SUM(stat.NUM_ROWS) AS SCHEMA_TABLE_ROWS'; + } + $sql .= ' + FROM data_dictionary.SCHEMAS s'; + if ($force_stats) { + $engine_info = PMA_Util::cacheGet('drizzle_engines', true); + $stats_join = "LEFT JOIN (SELECT 0 NUM_ROWS) AS stat ON false"; + if (isset($engine_info['InnoDB']) + && $engine_info['InnoDB']['module_library'] == 'innobase' + ) { + $stats_join + = "LEFT JOIN data_dictionary.INNODB_SYS_TABLESTATS stat" + . " ON (t.ENGINE = 'InnoDB' AND stat.NAME" + . " = (t.TABLE_SCHEMA || '/') || t.TABLE_NAME)"; + } + + $sql .= " + LEFT JOIN data_dictionary.TABLES t + ON t.TABLE_SCHEMA = s.SCHEMA_NAME + $stats_join"; + } + $sql .= $sql_where_schema . ' + GROUP BY s.SCHEMA_NAME + ORDER BY ' . PMA_Util::backquote($sort_by) . ' ' . $sort_order + . $limit; + } else { + $sql = 'SELECT + s.SCHEMA_NAME, + s.DEFAULT_COLLATION_NAME'; + if ($force_stats) { + $sql .= ', + COUNT(t.TABLE_SCHEMA) AS SCHEMA_TABLES, + SUM(t.TABLE_ROWS) AS SCHEMA_TABLE_ROWS, + SUM(t.DATA_LENGTH) AS SCHEMA_DATA_LENGTH, + SUM(t.MAX_DATA_LENGTH) AS SCHEMA_MAX_DATA_LENGTH, + SUM(t.INDEX_LENGTH) AS SCHEMA_INDEX_LENGTH, + SUM(t.DATA_LENGTH + t.INDEX_LENGTH) + AS SCHEMA_LENGTH, + SUM(t.DATA_FREE) AS SCHEMA_DATA_FREE'; + } + $sql .= ' + FROM `information_schema`.SCHEMATA s'; + if ($force_stats) { + $sql .= ' + LEFT JOIN `information_schema`.TABLES t + ON BINARY t.TABLE_SCHEMA = BINARY s.SCHEMA_NAME'; + } + $sql .= $sql_where_schema . ' + GROUP BY BINARY s.SCHEMA_NAME + ORDER BY BINARY ' . PMA_Util::backquote($sort_by) + . ' ' . $sort_order + . $limit; + } + + $databases = $this->fetchResult($sql, 'SCHEMA_NAME', null, $link); + + $mysql_error = $this->getError($link); + if (! count($databases) && $GLOBALS['errno']) { + PMA_Util::mysqlDie($mysql_error, $sql); + } + + // display only databases also in official database list + // f.e. to apply hide_db and only_db + $drops = array_diff( + array_keys($databases), (array) $GLOBALS['pma']->databases + ); + if (count($drops)) { + foreach ($drops as $drop) { + unset($databases[$drop]); + } + unset($drop); + } + unset($sql_where_schema, $sql, $drops); + } else { + foreach ($GLOBALS['pma']->databases as $database_name) { + // MySQL forward compatibility + // so pma could use this array as if every server is of version >5.0 + // todo : remove and check the rest of the code for usage, + // MySQL 5.0 or higher is required for current PMA version + $databases[$database_name]['SCHEMA_NAME'] = $database_name; + + if ($force_stats) { + include_once './libraries/mysql_charsets.lib.php'; + + $databases[$database_name]['DEFAULT_COLLATION_NAME'] + = PMA_getDbCollation($database_name); + + // get additional info about tables + $databases[$database_name]['SCHEMA_TABLES'] = 0; + $databases[$database_name]['SCHEMA_TABLE_ROWS'] = 0; + $databases[$database_name]['SCHEMA_DATA_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_INDEX_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_LENGTH'] = 0; + $databases[$database_name]['SCHEMA_DATA_FREE'] = 0; + + $res = $this->query( + 'SHOW TABLE STATUS FROM ' + . PMA_Util::backquote($database_name) . ';' + ); + + while ($row = $this->fetchAssoc($res)) { + $databases[$database_name]['SCHEMA_TABLES']++; + $databases[$database_name]['SCHEMA_TABLE_ROWS'] + += $row['Rows']; + $databases[$database_name]['SCHEMA_DATA_LENGTH'] + += $row['Data_length']; + $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] + += $row['Max_data_length']; + $databases[$database_name]['SCHEMA_INDEX_LENGTH'] + += $row['Index_length']; + + // for InnoDB, this does not contain the number of + // overhead bytes but the total free space + if ('InnoDB' != $row['Engine']) { + $databases[$database_name]['SCHEMA_DATA_FREE'] + += $row['Data_free']; + } + $databases[$database_name]['SCHEMA_LENGTH'] + += $row['Data_length'] + $row['Index_length']; + } + $this->freeResult($res); + unset($res); + } + } + } + + + /** + * apply limit and order manually now + * (caused by older MySQL < 5 or $GLOBALS['cfg']['NaturalOrder']) + */ + if ($apply_limit_and_order_manual) { + $GLOBALS['callback_sort_order'] = $sort_order; + $GLOBALS['callback_sort_by'] = $sort_by; + usort($databases, 'PMA_usortComparisonCallback'); + unset($GLOBALS['callback_sort_order'], $GLOBALS['callback_sort_by']); + + /** + * now apply limit + */ + if ($limit_count) { + $databases = array_slice($databases, $limit_offset, $limit_count); + } + } + + return $databases; + } + + /** + * returns detailed array with all columns for given table in database, + * or all tables/databases + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param string $column name of specific column + * @param mixed $link mysql link resource + * + * @return array + */ + public function getColumnsFull($database = null, $table = null, + $column = null, $link = null + ) { + $columns = array(); + + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + $sql_wheres = array(); + $array_keys = array(); + + // get columns information from information_schema + if (null !== $database) { + $sql_wheres[] = '`TABLE_SCHEMA` = \'' + . PMA_Util::sqlAddSlashes($database) . '\' '; + } else { + $array_keys[] = 'TABLE_SCHEMA'; + } + if (null !== $table) { + $sql_wheres[] = '`TABLE_NAME` = \'' + . PMA_Util::sqlAddSlashes($table) . '\' '; + } else { + $array_keys[] = 'TABLE_NAME'; + } + if (null !== $column) { + $sql_wheres[] = '`COLUMN_NAME` = \'' + . PMA_Util::sqlAddSlashes($column) . '\' '; + } else { + $array_keys[] = 'COLUMN_NAME'; + } + + // for PMA bc: + // `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]` + if (PMA_DRIZZLE) { + $sql = "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, + column_name AS `Field`, + (CASE + WHEN character_maximum_length > 0 + THEN concat(lower(data_type), '(', character_maximum_length, ')') + WHEN numeric_precision > 0 OR numeric_scale > 0 + THEN concat(lower(data_type), '(', numeric_precision, + ',', numeric_scale, ')') + WHEN enum_values IS NOT NULL + THEN concat(lower(data_type), '(', enum_values, ')') + ELSE lower(data_type) END) + AS `Type`, + collation_name AS `Collation`, + (CASE is_nullable + WHEN 1 THEN 'YES' + ELSE 'NO' END) AS `Null`, + (CASE + WHEN is_used_in_primary THEN 'PRI' + ELSE '' END) AS `Key`, + column_default AS `Default`, + (CASE + WHEN is_auto_increment THEN 'auto_increment' + WHEN column_default_update + THEN 'on update ' || column_default_update + ELSE '' END) AS `Extra`, + NULL AS `Privileges`, + column_comment AS `Comment` + FROM data_dictionary.columns"; + } else { + $sql = ' + SELECT *, + `COLUMN_NAME` AS `Field`, + `COLUMN_TYPE` AS `Type`, + `COLLATION_NAME` AS `Collation`, + `IS_NULLABLE` AS `Null`, + `COLUMN_KEY` AS `Key`, + `COLUMN_DEFAULT` AS `Default`, + `EXTRA` AS `Extra`, + `PRIVILEGES` AS `Privileges`, + `COLUMN_COMMENT` AS `Comment` + FROM `information_schema`.`COLUMNS`'; + } + if (count($sql_wheres)) { + $sql .= "\n" . ' WHERE ' . implode(' AND ', $sql_wheres); + } + + $columns = $this->fetchResult($sql, $array_keys, null, $link); + unset($sql_wheres, $sql); + } else { + if (null === $database) { + foreach ($GLOBALS['pma']->databases as $database) { + $columns[$database] = $this->getColumnsFull( + $database, null, null, $link + ); + } + return $columns; + } elseif (null === $table) { + $tables = $this->getTables($database); + foreach ($tables as $table) { + $columns[$table] = $this->getColumnsFull( + $database, $table, null, $link + ); + } + return $columns; + } + + $sql = 'SHOW FULL COLUMNS FROM ' + . PMA_Util::backquote($database) . '.' . PMA_Util::backquote($table); + if (null !== $column) { + $sql .= " LIKE '" . PMA_Util::sqlAddSlashes($column, true) . "'"; + } + + $columns = $this->fetchResult($sql, 'Field', null, $link); + } + $ordinal_position = 1; + foreach ($columns as $column_name => $each_column) { + + // MySQL forward compatibility + // so pma could use this array as if every server is of version >5.0 + // todo : remove and check the rest of the code for usage, + // MySQL 5.0 or higher is required for current PMA version + $columns[$column_name]['COLUMN_NAME'] + =& $columns[$column_name]['Field']; + $columns[$column_name]['COLUMN_TYPE'] + =& $columns[$column_name]['Type']; + $columns[$column_name]['COLLATION_NAME'] + =& $columns[$column_name]['Collation']; + $columns[$column_name]['IS_NULLABLE'] + =& $columns[$column_name]['Null']; + $columns[$column_name]['COLUMN_KEY'] + =& $columns[$column_name]['Key']; + $columns[$column_name]['COLUMN_DEFAULT'] + =& $columns[$column_name]['Default']; + $columns[$column_name]['EXTRA'] + =& $columns[$column_name]['Extra']; + $columns[$column_name]['PRIVILEGES'] + =& $columns[$column_name]['Privileges']; + $columns[$column_name]['COLUMN_COMMENT'] + =& $columns[$column_name]['Comment']; + + $columns[$column_name]['TABLE_CATALOG'] = null; + $columns[$column_name]['TABLE_SCHEMA'] = $database; + $columns[$column_name]['TABLE_NAME'] = $table; + $columns[$column_name]['ORDINAL_POSITION'] = $ordinal_position; + $columns[$column_name]['DATA_TYPE'] + = substr( + $columns[$column_name]['COLUMN_TYPE'], + 0, + strpos($columns[$column_name]['COLUMN_TYPE'], '(') + ); + /** + * @todo guess CHARACTER_MAXIMUM_LENGTH from COLUMN_TYPE + */ + $columns[$column_name]['CHARACTER_MAXIMUM_LENGTH'] = null; + /** + * @todo guess CHARACTER_OCTET_LENGTH from CHARACTER_MAXIMUM_LENGTH + */ + $columns[$column_name]['CHARACTER_OCTET_LENGTH'] = null; + $columns[$column_name]['NUMERIC_PRECISION'] = null; + $columns[$column_name]['NUMERIC_SCALE'] = null; + $columns[$column_name]['CHARACTER_SET_NAME'] + = substr( + $columns[$column_name]['COLLATION_NAME'], + 0, + strpos($columns[$column_name]['COLLATION_NAME'], '_') + ); + + $ordinal_position++; + } + + if (null !== $column) { + reset($columns); + $columns = current($columns); + } + + return $columns; + } + + /** + * Returns SQL query for fetching columns for a table + * + * The 'Key' column is not calculated properly, use $GLOBALS['dbi']->getColumns() + * to get correct values. + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param string $column name of column, null to show all columns + * @param boolean $full whether to return full info or only column names + * + * @see getColumns() + * + * @return string + */ + public function getColumnsSql($database, $table, $column = null, $full = false) + { + if (PMA_DRIZZLE) { + // `Key` column: + // * used in primary key => PRI + // * unique one-column => UNI + // * indexed, one-column or first in multi-column => MUL + // Promotion of UNI to PRI in case no promary index exists + // is done after query is executed + $sql = "SELECT + column_name AS `Field`, + (CASE + WHEN character_maximum_length > 0 + THEN concat(lower(data_type), '(', character_maximum_length, ')') + WHEN numeric_precision > 0 OR numeric_scale > 0 + THEN concat(lower(data_type), '(', numeric_precision, + ',', numeric_scale, ')') + WHEN enum_values IS NOT NULL + THEN concat(lower(data_type), '(', enum_values, ')') + ELSE lower(data_type) END) + AS `Type`, + " . ($full ? " + collation_name AS `Collation`," : '') . " + (CASE is_nullable + WHEN 1 THEN 'YES' + ELSE 'NO' END) AS `Null`, + (CASE + WHEN is_used_in_primary THEN 'PRI' + WHEN is_unique AND NOT is_multi THEN 'UNI' + WHEN is_indexed + AND (NOT is_multi OR is_first_in_multi) THEN 'MUL' + ELSE '' END) AS `Key`, + column_default AS `Default`, + (CASE + WHEN is_auto_increment THEN 'auto_increment' + WHEN column_default_update <> '' + THEN 'on update ' || column_default_update + ELSE '' END) AS `Extra` + " . ($full ? " , + NULL AS `Privileges`, + column_comment AS `Comment`" : '') . " + FROM data_dictionary.columns + WHERE table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' + AND table_name = '" . PMA_Util::sqlAddSlashes($table) . "' + " . (($column != null) ? " + AND column_name = '" . PMA_Util::sqlAddSlashes($column) . "'" : ''); + // ORDER BY ordinal_position + } else { + $sql = 'SHOW ' . ($full ? 'FULL' : '') . ' COLUMNS FROM ' + . PMA_Util::backquote($database) . '.' . PMA_Util::backquote($table) + . (($column != null) ? "LIKE '" + . PMA_Util::sqlAddSlashes($column, true) . "'" : ''); + } + return $sql; + } + + /** + * Returns descriptions of columns in given table (all or given by $column) + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param string $column name of column, null to show all columns + * @param boolean $full whether to return full info or only column names + * @param mixed $link mysql link resource + * + * @return false|array array indexed by column names or, + * if $column is given, flat array description + */ + public function getColumns($database, $table, $column = null, $full = false, + $link = null + ) { + $sql = $this->getColumnsSql($database, $table, $column, $full); + $fields = $this->fetchResult($sql, 'Field', null, $link); + if (! is_array($fields) || count($fields) == 0) { + return null; + } + if (PMA_DRIZZLE) { + // fix Key column, it's much simpler in PHP than in SQL + $has_pk = false; + $has_pk_candidates = false; + foreach ($fields as $f) { + if ($f['Key'] == 'PRI') { + $has_pk = true; + break; + } else if ($f['Null'] == 'NO' + && ($f['Key'] == 'MUL' + || $f['Key'] == 'UNI') + ) { + $has_pk_candidates = true; + } + } + if (! $has_pk && $has_pk_candidates) { + // check whether we can promote some unique index to PRI + $sql = " + SELECT i.index_name, p.column_name + FROM data_dictionary.indexes i + JOIN data_dictionary.index_parts p + USING (table_schema, table_name) + WHERE i.table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' + AND i.table_name = '" . PMA_Util::sqlAddSlashes($table) . "' + AND i.is_unique + AND NOT i.is_nullable"; + $fs = $this->fetchResult($sql, 'index_name', null, $link); + $fs = $fs ? array_shift($fs) : array(); + foreach ($fs as $f) { + $fields[$f]['Key'] = 'PRI'; + } + } + } + + return ($column != null) ? array_shift($fields) : $fields; + } + + /** + * Returns all column names in given table + * + * @param string $database name of database + * @param string $table name of table to retrieve columns from + * @param mixed $link mysql link resource + * + * @return null|array + */ + public function getColumnNames($database, $table, $link = null) + { + $sql = $this->getColumnsSql($database, $table); + // We only need the 'Field' column which contains the table's column names + $fields = array_keys($this->fetchResult($sql, 'Field', null, $link)); + + if ( ! is_array($fields) || count($fields) == 0 ) { + return null; + } + return $fields; + } + + /** + * Returns SQL for fetching information on table indexes (SHOW INDEXES) + * + * @param string $database name of database + * @param string $table name of the table whose indexes are to be retreived + * @param string $where additional conditions for WHERE + * + * @return array $indexes + */ + public function getTableIndexesSql($database, $table, $where = null) + { + if (PMA_DRIZZLE) { + $sql = "SELECT + ip.table_name AS `Table`, + (NOT ip.is_unique) AS Non_unique, + ip.index_name AS Key_name, + ip.sequence_in_index+1 AS Seq_in_index, + ip.column_name AS Column_name, + (CASE + WHEN i.index_type = 'BTREE' THEN 'A' + ELSE NULL END) AS Collation, + NULL AS Cardinality, + compare_length AS Sub_part, + NULL AS Packed, + ip.is_nullable AS `Null`, + i.index_type AS Index_type, + NULL AS Comment, + i.index_comment AS Index_comment + FROM data_dictionary.index_parts ip + LEFT JOIN data_dictionary.indexes i + USING (table_schema, table_name, index_name) + WHERE table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' + AND table_name = '" . PMA_Util::sqlAddSlashes($table) . "' + "; + } else { + $sql = 'SHOW INDEXES FROM ' . PMA_Util::backquote($database) . '.' + . PMA_Util::backquote($table); + } + if ($where) { + $sql .= (PMA_DRIZZLE ? ' AND (' : ' WHERE (') . $where . ')'; + } + return $sql; + } + + /** + * Returns indexes of a table + * + * @param string $database name of database + * @param string $table name of the table whose indexes are to be retrieved + * @param mixed $link mysql link resource + * + * @return array $indexes + */ + public function getTableIndexes($database, $table, $link = null) + { + $sql = $this->getTableIndexesSql($database, $table); + $indexes = $this->fetchResult($sql, null, null, $link); + + if (! is_array($indexes) || count($indexes) < 1) { + return array(); + } + return $indexes; + } + + /** + * returns value of given mysql server variable + * + * @param string $var mysql server variable name + * @param int $type PMA_DBI_GETVAR_SESSION|PMA_DBI_GETVAR_GLOBAL + * @param mixed $link mysql link resource|object + * + * @return mixed value for mysql server variable + */ + public function getVariable($var, $type = PMA_DBI_GETVAR_SESSION, $link = null) + { + if ($link === null) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return false; + } + } + + switch ($type) { + case PMA_DBI_GETVAR_SESSION: + $modifier = ' SESSION'; + break; + case PMA_DBI_GETVAR_GLOBAL: + $modifier = ' GLOBAL'; + break; + default: + $modifier = ''; + } + return $this->fetchValue( + 'SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 0, 1, $link + ); + } + + /** + * Function called just after a connection to the MySQL database server has + * been established. It sets the connection collation, and determins the + * version of MySQL which is running. + * + * @param mixed $link mysql link resource|object + * @param boolean $is_controluser whether link is for control user + * + * @return void + */ + public function postConnect($link, $is_controluser = false) + { + if (! defined('PMA_MYSQL_INT_VERSION')) { + if (PMA_Util::cacheExists('PMA_MYSQL_INT_VERSION', true)) { + define( + 'PMA_MYSQL_INT_VERSION', + PMA_Util::cacheGet('PMA_MYSQL_INT_VERSION', true) + ); + define( + 'PMA_MYSQL_MAJOR_VERSION', + PMA_Util::cacheGet('PMA_MYSQL_MAJOR_VERSION', true) + ); + define( + 'PMA_MYSQL_STR_VERSION', + PMA_Util::cacheGet('PMA_MYSQL_STR_VERSION', true) + ); + define( + 'PMA_MYSQL_VERSION_COMMENT', + PMA_Util::cacheGet('PMA_MYSQL_VERSION_COMMENT', true) + ); + } else { + $version = $this->fetchSingleRow( + 'SELECT @@version, @@version_comment', + 'ASSOC', + $link + ); + + if ($version) { + $match = explode('.', $version['@@version']); + define('PMA_MYSQL_MAJOR_VERSION', (int)$match[0]); + define( + 'PMA_MYSQL_INT_VERSION', + (int) sprintf( + '%d%02d%02d', $match[0], $match[1], intval($match[2]) + ) + ); + define('PMA_MYSQL_STR_VERSION', $version['@@version']); + define( + 'PMA_MYSQL_VERSION_COMMENT', + $version['@@version_comment'] + ); + } else { + define('PMA_MYSQL_INT_VERSION', 50015); + define('PMA_MYSQL_MAJOR_VERSION', 5); + define('PMA_MYSQL_STR_VERSION', '5.00.15'); + define('PMA_MYSQL_VERSION_COMMENT', ''); + } + PMA_Util::cacheSet( + 'PMA_MYSQL_INT_VERSION', + PMA_MYSQL_INT_VERSION, + true + ); + PMA_Util::cacheSet( + 'PMA_MYSQL_MAJOR_VERSION', + PMA_MYSQL_MAJOR_VERSION, + true + ); + PMA_Util::cacheSet( + 'PMA_MYSQL_STR_VERSION', + PMA_MYSQL_STR_VERSION, + true + ); + PMA_Util::cacheSet( + 'PMA_MYSQL_VERSION_COMMENT', + PMA_MYSQL_VERSION_COMMENT, + true + ); + } + // detect Drizzle by version number: + // <year>.<month>.<build number>(.<patch rev) + define('PMA_DRIZZLE', PMA_MYSQL_MAJOR_VERSION >= 2009); + } + + // Skip charsets for Drizzle + if (!PMA_DRIZZLE) { + if (! empty($GLOBALS['collation_connection'])) { + $this->query( + "SET CHARACTER SET 'utf8';", $link, PMA_DBI_QUERY_STORE + ); + $set_collation_con_query = "SET collation_connection = '" + . PMA_Util::sqlAddSlashes($GLOBALS['collation_connection']) + . "';"; + $this->query( + $set_collation_con_query, + $link, + PMA_DBI_QUERY_STORE + ); + } else { + $this->query( + "SET NAMES 'utf8' COLLATE 'utf8_general_ci';", + $link, + PMA_DBI_QUERY_STORE + ); + } + } + + // Cache plugin list for Drizzle + if (PMA_DRIZZLE && !PMA_Util::cacheExists('drizzle_engines', true)) { + $sql = "SELECT p.plugin_name, m.module_library + FROM data_dictionary.plugins p + JOIN data_dictionary.modules m USING (module_name) + WHERE p.plugin_type = 'StorageEngine' + AND p.plugin_name NOT IN ('FunctionEngine', 'schema') + AND p.is_active = 'YES'"; + $engines = $this->fetchResult($sql, 'plugin_name', null, $link); + PMA_Util::cacheSet('drizzle_engines', $engines, true); + } + } + + /** + * returns a single value from the given result or query, + * if the query or the result has more than one row or field + * the first field of the first row is returned + * + * <code> + * $sql = 'SELECT `name` FROM `user` WHERE `id` = 123'; + * $user_name = $GLOBALS['dbi']->fetchValue($sql); + * // produces + * // $user_name = 'John Doe' + * </code> + * + * @param string|mysql_result $result query or mysql result + * @param integer $row_number row to fetch the value from, + * starting at 0, with 0 being default + * @param integer|string $field field to fetch the value from, + * starting at 0, with 0 being default + * @param resource $link mysql link + * + * @return mixed value of first field in first row from result + * or false if not found + */ + public function fetchValue($result, $row_number = 0, $field = 0, $link = null) + { + $value = false; + + if (is_string($result)) { + $result = $this->tryQuery($result, $link, PMA_DBI_QUERY_STORE, false); + } + + // return false if result is empty or false + // or requested row is larger than rows in result + if ($this->numRows($result) < ($row_number + 1)) { + return $value; + } + + // if $field is an integer use non associative mysql fetch function + if (is_int($field)) { + $fetch_function = 'fetchRow'; + } else { + $fetch_function = 'fetchAssoc'; + } + + // get requested row + for ($i = 0; $i <= $row_number; $i++) { + $row = $this->$fetch_function($result); + } + $this->freeResult($result); + + // return requested field + if (isset($row[$field])) { + $value = $row[$field]; + } + unset($row); + + return $value; + } + + /** + * returns only the first row from the result + * + * <code> + * $sql = 'SELECT * FROM `user` WHERE `id` = 123'; + * $user = $GLOBALS['dbi']->fetchSingleRow($sql); + * // produces + * // $user = array('id' => 123, 'name' => 'John Doe') + * </code> + * + * @param string|mysql_result $result query or mysql result + * @param string $type NUM|ASSOC|BOTH + * returned array should either numeric + * associativ or booth + * @param resource $link mysql link + * + * @return array|boolean first row from result + * or false if result is empty + */ + public function fetchSingleRow($result, $type = 'ASSOC', $link = null) + { + if (is_string($result)) { + $result = $this->tryQuery($result, $link, PMA_DBI_QUERY_STORE, false); + } + + // return null if result is empty or false + if (! $this->numRows($result)) { + return false; + } + + switch ($type) { + case 'NUM' : + $fetch_function = 'fetchRow'; + break; + case 'ASSOC' : + $fetch_function = 'fetchAssoc'; + break; + case 'BOTH' : + default : + $fetch_function = 'fetchArray'; + break; + } + + $row = $this->$fetch_function($result); + $this->freeResult($result); + return $row; + } + + /** + * returns all rows in the resultset in one array + * + * <code> + * $sql = 'SELECT * FROM `user`'; + * $users = $GLOBALS['dbi']->fetchResult($sql); + * // produces + * // $users[] = array('id' => 123, 'name' => 'John Doe') + * + * $sql = 'SELECT `id`, `name` FROM `user`'; + * $users = $GLOBALS['dbi']->fetchResult($sql, 'id'); + * // produces + * // $users['123'] = array('id' => 123, 'name' => 'John Doe') + * + * $sql = 'SELECT `id`, `name` FROM `user`'; + * $users = $GLOBALS['dbi']->fetchResult($sql, 0); + * // produces + * // $users['123'] = array(0 => 123, 1 => 'John Doe') + * + * $sql = 'SELECT `id`, `name` FROM `user`'; + * $users = $GLOBALS['dbi']->fetchResult($sql, 'id', 'name'); + * // or + * $users = $GLOBALS['dbi']->fetchResult($sql, 0, 1); + * // produces + * // $users['123'] = 'John Doe' + * + * $sql = 'SELECT `name` FROM `user`'; + * $users = $GLOBALS['dbi']->fetchResult($sql); + * // produces + * // $users[] = 'John Doe' + * + * $sql = 'SELECT `group`, `name` FROM `user`' + * $users = $GLOBALS['dbi']->fetchResult($sql, array('group', null), 'name'); + * // produces + * // $users['admin'][] = 'John Doe' + * + * $sql = 'SELECT `group`, `name` FROM `user`' + * $users = $GLOBALS['dbi']->fetchResult($sql, array('group', 'name'), 'id'); + * // produces + * // $users['admin']['John Doe'] = '123' + * </code> + * + * @param string|mysql_result $result query or mysql result + * @param string|integer $key field-name or offset + * used as key for array + * @param string|integer $value value-name or offset + * used as value for array + * @param resource $link mysql link + * @param mixed $options query options + * + * @return array resultrows or values indexed by $key + */ + public function fetchResult($result, $key = null, $value = null, + $link = null, $options = 0 + ) { + $resultrows = array(); + + if (is_string($result)) { + $result = $this->tryQuery($result, $link, $options, false); + } + + // return empty array if result is empty or false + if (! $result) { + return $resultrows; + } + + $fetch_function = 'fetchAssoc'; + + // no nested array if only one field is in result + if (null === $key && 1 === $this->numFields($result)) { + $value = 0; + $fetch_function = 'fetchRow'; + } + + // if $key is an integer use non associative mysql fetch function + if (is_int($key)) { + $fetch_function = 'fetchRow'; + } + + if (null === $key && null === $value) { + while ($row = $this->$fetch_function($result)) { + $resultrows[] = $row; + } + } elseif (null === $key) { + while ($row = $this->$fetch_function($result)) { + $resultrows[] = $row[$value]; + } + } elseif (null === $value) { + if (is_array($key)) { + while ($row = $this->$fetch_function($result)) { + $result_target =& $resultrows; + foreach ($key as $key_index) { + if (null === $key_index) { + $result_target =& $result_target[]; + continue; + } + + if (! isset($result_target[$row[$key_index]])) { + $result_target[$row[$key_index]] = array(); + } + $result_target =& $result_target[$row[$key_index]]; + } + $result_target = $row; + } + } else { + while ($row = $this->$fetch_function($result)) { + $resultrows[$row[$key]] = $row; + } + } + } else { + if (is_array($key)) { + while ($row = $this->$fetch_function($result)) { + $result_target =& $resultrows; + foreach ($key as $key_index) { + if (null === $key_index) { + $result_target =& $result_target[]; + continue; + } + + if (! isset($result_target[$row[$key_index]])) { + $result_target[$row[$key_index]] = array(); + } + $result_target =& $result_target[$row[$key_index]]; + } + $result_target = $row[$value]; + } + } else { + while ($row = $this->$fetch_function($result)) { + $resultrows[$row[$key]] = $row[$value]; + } + } + } + + $this->freeResult($result); + return $resultrows; + } + + /** + * Get supported SQL compatibility modes + * + * @return array supported SQL compatibility modes + */ + public function getCompatibilities() + { + // Drizzle doesn't support compatibility modes + if (PMA_DRIZZLE) { + return array(); + } + + $compats = array('NONE'); + $compats[] = 'ANSI'; + $compats[] = 'DB2'; + $compats[] = 'MAXDB'; + $compats[] = 'MYSQL323'; + $compats[] = 'MYSQL40'; + $compats[] = 'MSSQL'; + $compats[] = 'ORACLE'; + // removed; in MySQL 5.0.33, this produces exports that + // can't be read by POSTGRESQL (see our bug #1596328) + //$compats[] = 'POSTGRESQL'; + $compats[] = 'TRADITIONAL'; + + return $compats; + } + + /** + * returns warnings for last query + * + * @param resource $link mysql link resource + * + * @return array warnings + */ + public function getWarnings($link = null) + { + if (empty($link)) { + if (isset($GLOBALS['userlink'])) { + $link = $GLOBALS['userlink']; + } else { + return array(); + } + } + + return $this->fetchResult('SHOW WARNINGS', null, null, $link); + } + + /** + * returns an array of PROCEDURE or FUNCTION names for a db + * + * @param string $db db name + * @param string $which PROCEDURE | FUNCTION + * @param resource $link mysql link + * + * @return array the procedure names or function names + */ + public function getProceduresOrFunctions($db, $which, $link = null) + { + if (PMA_DRIZZLE) { + // Drizzle doesn't support functions and procedures + return array(); + } + $shows = $this->fetchResult( + 'SHOW ' . $which . ' STATUS;', null, null, $link + ); + $result = array(); + foreach ($shows as $one_show) { + if ($one_show['Db'] == $db && $one_show['Type'] == $which) { + $result[] = $one_show['Name']; + } + } + return($result); + } + + /** + * returns the definition of a specific PROCEDURE, FUNCTION, EVENT or VIEW + * + * @param string $db db name + * @param string $which PROCEDURE | FUNCTION | EVENT | VIEW + * @param string $name the procedure|function|event|view name + * @param resource $link mysql link + * + * @return string the definition + */ + public function getDefinition($db, $which, $name, $link = null) + { + $returned_field = array( + 'PROCEDURE' => 'Create Procedure', + 'FUNCTION' => 'Create Function', + 'EVENT' => 'Create Event', + 'VIEW' => 'Create View' + ); + $query = 'SHOW CREATE ' . $which . ' ' + . PMA_Util::backquote($db) . '.' + . PMA_Util::backquote($name); + return($this->fetchValue($query, 0, $returned_field[$which])); + } + + /** + * returns details about the TRIGGERs for a specific table or database + * + * @param string $db db name + * @param string $table table name + * @param string $delimiter the delimiter to use (may be empty) + * + * @return array information about triggers (may be empty) + */ + public function getTriggers($db, $table = '', $delimiter = '//') + { + if (PMA_DRIZZLE) { + // Drizzle doesn't support triggers + return array(); + } + + $result = array(); + if (! $GLOBALS['cfg']['Server']['DisableIS']) { + // Note: in http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html + // their example uses WHERE TRIGGER_SCHEMA='dbname' so let's use this + // instead of WHERE EVENT_OBJECT_SCHEMA='dbname' + $query = 'SELECT TRIGGER_SCHEMA, TRIGGER_NAME, EVENT_MANIPULATION' + . ', EVENT_OBJECT_TABLE, ACTION_TIMING, ACTION_STATEMENT' + . ', EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE, DEFINER' + . ' FROM information_schema.TRIGGERS' + . ' WHERE TRIGGER_SCHEMA= \'' . PMA_Util::sqlAddSlashes($db) . '\''; + + if (! empty($table)) { + $query .= " AND EVENT_OBJECT_TABLE = '" + . PMA_Util::sqlAddSlashes($table) . "';"; + } + } else { + $query = "SHOW TRIGGERS FROM " . PMA_Util::backquote($db); + if (! empty($table)) { + $query .= " LIKE '" . PMA_Util::sqlAddSlashes($table, true) . "';"; + } + } + + if ($triggers = $this->fetchResult($query)) { + foreach ($triggers as $trigger) { + if ($GLOBALS['cfg']['Server']['DisableIS']) { + $trigger['TRIGGER_NAME'] = $trigger['Trigger']; + $trigger['ACTION_TIMING'] = $trigger['Timing']; + $trigger['EVENT_MANIPULATION'] = $trigger['Event']; + $trigger['EVENT_OBJECT_TABLE'] = $trigger['Table']; + $trigger['ACTION_STATEMENT'] = $trigger['Statement']; + $trigger['DEFINER'] = $trigger['Definer']; + } + $one_result = array(); + $one_result['name'] = $trigger['TRIGGER_NAME']; + $one_result['table'] = $trigger['EVENT_OBJECT_TABLE']; + $one_result['action_timing'] = $trigger['ACTION_TIMING']; + $one_result['event_manipulation'] = $trigger['EVENT_MANIPULATION']; + $one_result['definition'] = $trigger['ACTION_STATEMENT']; + $one_result['definer'] = $trigger['DEFINER']; + + // do not prepend the schema name; this way, importing the + // definition into another schema will work + $one_result['full_trigger_name'] = PMA_Util::backquote( + $trigger['TRIGGER_NAME'] + ); + $one_result['drop'] = 'DROP TRIGGER IF EXISTS ' + . $one_result['full_trigger_name']; + $one_result['create'] = 'CREATE TRIGGER ' + . $one_result['full_trigger_name'] . ' ' + . $trigger['ACTION_TIMING']. ' ' + . $trigger['EVENT_MANIPULATION'] + . ' ON ' . PMA_Util::backquote($trigger['EVENT_OBJECT_TABLE']) + . "\n" . ' FOR EACH ROW ' + . $trigger['ACTION_STATEMENT'] . "\n" . $delimiter . "\n"; + + $result[] = $one_result; + } + } + + // Sort results by name + $name = array(); + foreach ($result as $value) { + $name[] = $value['name']; + } + array_multisort($name, SORT_ASC, $result); + + return($result); + } + + /** + * Formats database error message in a friendly way. + * This is needed because some errors messages cannot + * be obtained by mysql_error(). + * + * @param int $error_number Error code + * @param string $error_message Error message as returned by server + * + * @return string HML text with error details + */ + public function formatError($error_number, $error_message) + { + if (! empty($error_message)) { + $error_message = $this->convertMessage($error_message); + } + + $error_message = htmlspecialchars($error_message); + + $error = '#' . ((string) $error_number); + + if ($error_number == 2002) { + $error .= ' - ' . $error_message; + $error .= '<br />'; + $error .= __( + 'The server is not responding (or the local server\'s socket' + . ' is not correctly configured).' + ); + } elseif ($error_number == 2003) { + $error .= ' - ' . $error_message; + $error .= '<br />' . __('The server is not responding.'); + } elseif ($error_number == 1005) { + if (strpos($error_message, 'errno: 13') !== false) { + $error .= ' - ' . $error_message; + $error .= '<br />' + . __('Please check privileges of directory containing database.'); + } else { + /* InnoDB contraints, see + * http://dev.mysql.com/doc/refman/5.0/en/ + * innodb-foreign-key-constraints.html + */ + $error .= ' - ' . $error_message . + ' (<a href="server_engines.php' . + PMA_generate_common_url( + array('engine' => 'InnoDB', 'page' => 'Status') + ) . '">' . __('Details…') . '</a>)'; + } + } else { + $error .= ' - ' . $error_message; + } + + return $error; + } + + /** + * returns true (int > 0) if current user is superuser + * otherwise 0 + * + * @return bool Whether use is a superuser + */ + public function isSuperuser() + { + if (PMA_Util::cacheExists('is_superuser', true)) { + return PMA_Util::cacheGet('is_superuser', true); + } + + // when connection failed we don't have a $userlink + if (isset($GLOBALS['userlink'])) { + if (PMA_DRIZZLE) { + // Drizzle has no authorization by default, so when no plugin is + // enabled everyone is a superuser + // Known authorization libraries: regex_policy, simple_user_policy + // Plugins limit object visibility (dbs, tables, processes), we can + // safely assume we always deal with superuser + $result = true; + } else { + // check access to mysql.user table + $result = (bool) $GLOBALS['dbi']->tryQuery( + 'SELECT COUNT(*) FROM mysql.user', + $GLOBALS['userlink'], + PMA_DBI_QUERY_STORE + ); + } + PMA_Util::cacheSet('is_superuser', $result, true); + } else { + PMA_Util::cacheSet('is_superuser', false, true); + } + + return PMA_Util::cacheGet('is_superuser', true); + } + + /** + * Checks whether given schema is a system schema: information_schema + * (MySQL and Drizzle) or data_dictionary (Drizzle) + * + * @param string $schema_name Name of schema (database) to test + * @param bool $test_for_mysql_schema Whether 'mysql' schema should + * be treated the same as IS and DD + * + * @return bool + */ + public function isSystemSchema($schema_name, $test_for_mysql_schema = false) + { + return strtolower($schema_name) == 'information_schema' + || (!PMA_DRIZZLE && strtolower($schema_name) == 'performance_schema') + || (PMA_DRIZZLE && strtolower($schema_name) == 'data_dictionary') + || ($test_for_mysql_schema && !PMA_DRIZZLE && $schema_name == 'mysql'); + } + + /** + * connects to the database server + * + * @param string $user user name + * @param string $password user password + * @param bool $is_controluser whether this is a control user connection + * @param array $server host/port/socket/persistent + * @param bool $auxiliary_connection (when true, don't go back to login if + * connection fails) + * + * @return mixed false on error or a connection object on success + */ + public function connect( + $user, $password, $is_controluser = false, $server = null, + $auxiliary_connection = false + ) { + return $this->_extension->connect( + $user, $password, $is_controluser, $server, $auxiliary_connection + ); + } + + /** + * selects given database + * + * @param string $dbname database name to select + * @param object $link connection object + * + * @return boolean + */ + public function selectDb($dbname, $link = null) + { + return $this->_extension->selectDb($dbname, $link); + } + + /** + * returns array of rows with associative and numeric keys from $result + * + * @param object $result result set identifier + * + * @return array + */ + public function fetchArray($result) + { + return $this->_extension->fetchArray($result); + } + + /** + * returns array of rows with associative keys from $result + * + * @param object $result result set identifier + * + * @return array + */ + public function fetchAssoc($result) + { + return $this->_extension->fetchAssoc($result); + } + + /** + * returns array of rows with numeric keys from $result + * + * @param object $result result set identifier + * + * @return array + */ + public function fetchRow($result) + { + return $this->_extension->fetchRow($result); + } + + /** + * Adjusts the result pointer to an arbitrary row in the result + * + * @param object $result database result + * @param integer $offset offset to seek + * + * @return bool true on success, false on failure + */ + public function dataSeek($result, $offset) + { + return $this->_extension->dataSeek($result, $offset); + } + + /** + * Frees memory associated with the result + * + * @param object $result database result + * + * @return void + */ + public function freeResult($result) + { + $this->_extension->freeResult($result); + } + + /** + * Check if there are any more query results from a multi query + * + * @param object $link the connection object + * + * @return bool true or false + */ + public function moreResults($link = null) + { + return $this->_extension->moreResults($link = null); + } + + /** + * Prepare next result from multi_query + * + * @param object $link the connection object + * + * @return bool true or false + */ + public function nextResult($link = null) + { + return $this->_extension->nextResult($link = null); + } + + /** + * Store the result returned from multi query + * + * @return mixed false when empty results / result set when not empty + */ + public function storeResult() + { + return $this->_extension->storeResult(); + } + + /** + * Returns a string representing the type of connection used + * + * @param object $link mysql link + * + * @return string type of connection used + */ + public function getHostInfo($link = null) + { + return $this->_extension->getHostInfo($link); + } + + /** + * Returns the version of the MySQL protocol used + * + * @param object $link mysql link + * + * @return integer version of the MySQL protocol used + */ + public function getProtoInfo($link = null) + { + return $this->_extension->getProtoInfo($link); + } + + /** + * returns a string that represents the client library version + * + * @return string MySQL client library version + */ + public function getClientInfo() + { + return $this->_extension->getClientInfo(); + } + + /** + * returns last error message or false if no errors occured + * + * @param object $link connection link + * + * @return string|bool $error or false + */ + public function getError($link = null) + { + return $this->_extension->getError($link); + } + + /** + * returns the number of rows returned by last query + * + * @param object $result result set identifier + * + * @return string|int + */ + public function numRows($result) + { + return $this->_extension->numRows($result); + } + + /** + * returns last inserted auto_increment id for given $link + * or $GLOBALS['userlink'] + * + * @param object $link the connection object + * + * @return string|int + */ + public function insertId($link = null) + { + return $this->_extension->insertId($link); + } + + /** + * returns the number of rows affected by last query + * + * @param object $link the connection object + * @param bool $get_from_cache whether to retrieve from cache + * + * @return string|int + */ + public function affectedRows($link = null, $get_from_cache = true) + { + return $this->_extension->affectedRows($link, $get_from_cache); + } + + /** + * returns metainfo for fields in $result + * + * @param object $result result set identifier + * + * @return array meta info for fields in $result + */ + public function getFieldsMeta($result) + { + return $this->_extension->getFieldsMeta($result); + } + + /** + * return number of fields in given $result + * + * @param object $result result set identifier + * + * @return int field count + */ + public function numFields($result) + { + return $this->_extension->numFields($result); + } + + /** + * returns the length of the given field $i in $result + * + * @param object $result result set identifier + * @param int $i field + * + * @return int length of field + */ + public function fieldLen($result, $i) + { + return $this->_extension->fieldLen($result, $i); + } + + /** + * returns name of $i. field in $result + * + * @param object $result result set identifier + * @param int $i field + * + * @return string name of $i. field in $result + */ + public function fieldName($result, $i) + { + return $this->_extension->fieldName($result, $i); + } + + /** + * returns concatenated string of human readable field flags + * + * @param object $result result set identifier + * @param int $i field + * + * @return string field flags + */ + public function fieldFlags($result, $i) + { + return $this->_extension->fieldFlags($result, $i); + } +} +?> diff --git a/libraries/DbSearch.class.php b/libraries/DbSearch.class.php index a13541faf1..9f474715da 100644 --- a/libraries/DbSearch.class.php +++ b/libraries/DbSearch.class.php @@ -92,7 +92,7 @@ class PMA_DbSearch */ private function _setSearchParams() { - $this->_tables_names_only = PMA_DBI_getTables($this->_db); + $this->_tables_names_only = $GLOBALS['dbi']->getTables($this->_db); $this->_searchTypes = array( '1' => __('at least one of the words'), @@ -193,7 +193,7 @@ class PMA_DbSearch { $where_clause = ''; // Columns to select - $allColumns = PMA_DBI_getColumns($GLOBALS['db'], $table); + $allColumns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table); $likeClauses = array(); // Based on search type, decide like/regex & '%'/'' $like_or_regex = (($this->_criteriaSearchType == 4) ? 'REGEXP' : 'LIKE'); @@ -277,7 +277,7 @@ class PMA_DbSearch // Gets the SQL statements $newsearchsqls = $this->_getSearchSqls($each_table); // Executes the "COUNT" statement - $res_cnt = PMA_DBI_fetchValue($newsearchsqls['select_count']); + $res_cnt = $GLOBALS['dbi']->fetchValue($newsearchsqls['select_count']); $num_search_result_total += $res_cnt; // Gets the result row's HTML for a table $html_output .= $this->_getResultsRow( diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 9f3becf015..89ab0f5eda 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -2509,7 +2509,7 @@ class PMA_DisplayResults || ($_SESSION['tmp_user_values']['disp_direction'] == self::DISP_DIR_HORIZONTAL_FLIPPED); - while ($row = PMA_DBI_fetchRow($dt_result)) { + while ($row = $GLOBALS['dbi']->fetchRow($dt_result)) { // "vertical display" mode stuff $table_body_html .= $this->_getVerticalDisplaySupportSegments( @@ -2862,7 +2862,7 @@ class PMA_DisplayResults // PMA_mysql_fetch_fields returns BLOB in place of // TEXT fields type so we have to ensure it's really a BLOB - $field_flags = PMA_DBI_fieldFlags($dt_result, $i); + $field_flags = $GLOBALS['dbi']->fieldFlags($dt_result, $i); $vertical_display['data'][$row_no][$i] = $this->_getDataCellForBlobColumns( @@ -3843,7 +3843,7 @@ class PMA_DisplayResults ) { $is_analyse = $this->__get('is_analyse'); - $field_flags = PMA_DBI_fieldFlags($dt_result, $col_index); + $field_flags = $GLOBALS['dbi']->fieldFlags($dt_result, $col_index); if (stristr($field_flags, self::BINARY_FIELD) && ($GLOBALS['cfg']['ProtectBinary'] == 'all' || $GLOBALS['cfg']['ProtectBinary'] == 'noblob') @@ -4777,7 +4777,7 @@ class PMA_DisplayResults if ($sorted_column_index !== false) { // fetch first row of the result set - $row = PMA_DBI_fetchRow($dt_result); + $row = $GLOBALS['dbi']->fetchRow($dt_result); // initializing default arguments $default_function = '_mimeDefaultFunction'; @@ -4806,8 +4806,8 @@ class PMA_DisplayResults ); // fetch last row of the result set - PMA_DBI_dataSeek($dt_result, $this->__get('num_rows') - 1); - $row = PMA_DBI_fetchRow($dt_result); + $GLOBALS['dbi']->dataSeek($dt_result, $this->__get('num_rows') - 1); + $row = $GLOBALS['dbi']->fetchRow($dt_result); // check for non printable sorted row data $meta = $fields_meta[$sorted_column_index]; @@ -4830,7 +4830,7 @@ class PMA_DisplayResults ); // reset to first row for the loop in _getTableBody() - PMA_DBI_dataSeek($dt_result, 0); + $GLOBALS['dbi']->dataSeek($dt_result, 0); // we could also use here $sort_expression_nodirection return ' [' . htmlspecialchars($sort_column) @@ -5077,8 +5077,8 @@ class PMA_DisplayResults } // fetch last row of the result set - PMA_DBI_dataSeek($dt_result, $this->__get('num_rows') - 1); - $row = PMA_DBI_fetchRow($dt_result); + $GLOBALS['dbi']->dataSeek($dt_result, $this->__get('num_rows') - 1); + $row = $GLOBALS['dbi']->fetchRow($dt_result); // $clause_is_unique is needed by getTable() to generate the proper param // in the multi-edit and multi-delete form @@ -5091,7 +5091,7 @@ class PMA_DisplayResults ); // reset to first row for the loop in _getTableBody() - PMA_DBI_dataSeek($dt_result, 0); + $GLOBALS['dbi']->dataSeek($dt_result, 0); $links_html .= '<input type="hidden" name="clause_is_unique"' .' value="' . $clause_is_unique . '" />' . "\n"; @@ -5321,7 +5321,7 @@ class PMA_DisplayResults * the script it calls do not fail */ if (empty($_url_params['table']) && ! empty($_url_params['db'])) { - $_url_params['table'] = PMA_DBI_fetchValue("SHOW TABLES"); + $_url_params['table'] = $GLOBALS['dbi']->fetchValue("SHOW TABLES"); /* No result (probably no database selected) */ if ($_url_params['table'] === false) { unset($_url_params['table']); @@ -5574,15 +5574,15 @@ class PMA_DisplayResults . PMA_Util::backquote($map[$meta->name][1]) . $where_comparison; - $dispresult = PMA_DBI_tryQuery($dispsql, null, PMA_DBI_QUERY_STORE); + $dispresult = $GLOBALS['dbi']->tryQuery($dispsql, null, PMA_DBI_QUERY_STORE); - if ($dispresult && PMA_DBI_numRows($dispresult) > 0) { - list($dispval) = PMA_DBI_fetchRow($dispresult, 0); + if ($dispresult && $GLOBALS['dbi']->numRows($dispresult) > 0) { + list($dispval) = $GLOBALS['dbi']->fetchRow($dispresult, 0); } else { $dispval = __('Link not found'); } - @PMA_DBI_freeResult($dispresult); + @$GLOBALS['dbi']->freeResult($dispresult); } else { $dispval = ''; diff --git a/libraries/Index.class.php b/libraries/Index.class.php index 39553e2bf9..05cd990879 100644 --- a/libraries/Index.class.php +++ b/libraries/Index.class.php @@ -172,7 +172,7 @@ class PMA_Index return true; } - $_raw_indexes = PMA_DBI_getTableIndexes($schema, $table); + $_raw_indexes = $GLOBALS['dbi']->getTableIndexes($schema, $table); foreach ($_raw_indexes as $_each_index) { $_each_index['Schema'] = $schema; if (! isset(PMA_Index::$_registry[$schema][$table][$_each_index['Key_name']])) { diff --git a/libraries/List.class.php b/libraries/List.class.php index 1a0e644f67..1d8824ac6e 100644 --- a/libraries/List.class.php +++ b/libraries/List.class.php @@ -87,7 +87,7 @@ abstract class PMA_List extends ArrayObject $options = ''; foreach ($this as $each_item) { if (false === $include_information_schema - && PMA_isSystemSchema($each_item) + && $GLOBALS['dbi']->isSystemSchema($each_item) ) { continue; } diff --git a/libraries/List_Database.class.php b/libraries/List_Database.class.php index b3f6547209..8a6fc2bc48 100644 --- a/libraries/List_Database.class.php +++ b/libraries/List_Database.class.php @@ -122,18 +122,18 @@ class PMA_List_Database extends PMA_List $command = $this->command; } - $database_list = PMA_DBI_fetchResult($command, null, null, $this->db_link); - PMA_DBI_getError(); + $database_list = $GLOBALS['dbi']->fetchResult($command, null, null, $this->db_link); + $GLOBALS['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_fetchResult( + $database_list = $GLOBALS['dbi']->fetchResult( $command, null, null, $this->db_link ); - PMA_DBI_getError(); + $GLOBALS['dbi']->getError(); if ($GLOBALS['errno'] !== 0) { // failed! we will display a warning that phpMyAdmin could not safely @@ -244,7 +244,7 @@ class PMA_List_Database extends PMA_List WHERE `Select_priv` = 'Y' AND `User` IN ('" . PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . "', '')"; - $tmp_mydbs = PMA_DBI_fetchResult( + $tmp_mydbs = $GLOBALS['dbi']->fetchResult( $local_query, null, null, $GLOBALS['controllink'] ); if ($tmp_mydbs) { @@ -258,14 +258,14 @@ class PMA_List_Database extends PMA_List // populating $dblist[], as previous code did. But it is // now populated with actual database names instead of // with regular expressions. - $tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['controllink']); + $tmp_alldbs = $GLOBALS['dbi']->query('SHOW DATABASES;', $GLOBALS['controllink']); // all databases cases - part 2 if (isset($tmp_mydbs['%'])) { - while ($tmp_row = PMA_DBI_fetchRow($tmp_alldbs)) { + while ($tmp_row = $GLOBALS['dbi']->fetchRow($tmp_alldbs)) { $dblist[] = $tmp_row[0]; } // end while } else { - while ($tmp_row = PMA_DBI_fetchRow($tmp_alldbs)) { + while ($tmp_row = $GLOBALS['dbi']->fetchRow($tmp_alldbs)) { $tmp_db = $tmp_row[0]; if (isset($tmp_mydbs[$tmp_db]) && $tmp_mydbs[$tmp_db] == 1) { $dblist[] = $tmp_db; @@ -295,7 +295,7 @@ class PMA_List_Database extends PMA_List } // end if ... elseif ... } // end while } // end else - PMA_DBI_freeResult($tmp_alldbs); + $GLOBALS['dbi']->freeResult($tmp_alldbs); unset($tmp_mydbs); } // end if @@ -304,14 +304,14 @@ class PMA_List_Database extends PMA_List $local_query .= ' WHERE `Table_priv` LIKE \'%Select%\''; $local_query .= ' AND `User` = \''; $local_query .= PMA_Util::sqlAddSlashes($GLOBALS['cfg']['Server']['user']) . '\''; - $rs = PMA_DBI_tryQuery($local_query, $GLOBALS['controllink']); - if ($rs && @PMA_DBI_numRows($rs)) { - while ($row = PMA_DBI_fetchAssoc($rs)) { + $rs = $GLOBALS['dbi']->tryQuery($local_query, $GLOBALS['controllink']); + if ($rs && @$GLOBALS['dbi']->numRows($rs)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($rs)) { if (!in_array($row['Db'], $dblist)) { $dblist[] = $row['Db']; } } // end while - PMA_DBI_freeResult($rs); + $GLOBALS['dbi']->freeResult($rs); } // end if } } diff --git a/libraries/Menu.class.php b/libraries/Menu.class.php index 96e8085456..ce96802b93 100644 --- a/libraries/Menu.class.php +++ b/libraries/Menu.class.php @@ -240,7 +240,7 @@ class PMA_Menu */ private function _getTableTabs() { - $db_is_information_schema = PMA_isSystemSchema($this->_db); + $db_is_information_schema = $GLOBALS['dbi']->isSystemSchema($this->_db); $tbl_is_view = PMA_Table::isView($this->_db, $this->_table); $table_info_num_rows = PMA_Table::countRecords($this->_db, $this->_table); @@ -325,9 +325,9 @@ class PMA_Menu */ private function _getDbTabs() { - $db_is_information_schema = PMA_isSystemSchema($this->_db); - $num_tables = count(PMA_DBI_getTables($this->_db)); - $is_superuser = PMA_isSuperuser(); + $db_is_information_schema = $GLOBALS['dbi']->isSystemSchema($this->_db); + $num_tables = count($GLOBALS['dbi']->getTables($this->_db)); + $is_superuser = $GLOBALS['dbi']->isSuperuser(); /** * Gets the relation settings @@ -427,10 +427,10 @@ class PMA_Menu */ private function _getServerTabs() { - $is_superuser = PMA_isSuperuser(); + $is_superuser = $GLOBALS['dbi']->isSuperuser(); $binary_logs = null; if (!defined('PMA_DRIZZLE') || (defined('PMA_DRIZZLE') && ! PMA_DRIZZLE)) { - $binary_logs = PMA_DBI_fetchResult( + $binary_logs = $GLOBALS['dbi']->fetchResult( 'SHOW MASTER LOGS', 'Log_name', null, diff --git a/libraries/Partition.class.php b/libraries/Partition.class.php index 1c375205d1..512588588c 100644 --- a/libraries/Partition.class.php +++ b/libraries/Partition.class.php @@ -28,7 +28,7 @@ class PMA_Partition static public function getPartitionNames($db, $table) { if (PMA_Partition::havePartitioning()) { - return PMA_DBI_fetchResult( + return $GLOBALS['dbi']->fetchResult( "SELECT `PARTITION_NAME` FROM `information_schema`.`PARTITIONS`" . " WHERE `TABLE_SCHEMA` = '" . $db . "' AND `TABLE_NAME` = '" . $table . "'" @@ -55,14 +55,14 @@ class PMA_Partition if (! $already_checked) { if (PMA_MYSQL_INT_VERSION >= 50100) { if (PMA_MYSQL_INT_VERSION < 50600) { - if (PMA_DBI_fetchValue( + if ($GLOBALS['dbi']->fetchValue( "SHOW VARIABLES LIKE 'have_partitioning';" )) { $have_partitioning = true; } } else { // see http://dev.mysql.com/doc/refman/5.6/en/partitioning.html - $plugins = PMA_DBI_fetchResult("SHOW PLUGINS"); + $plugins = $GLOBALS['dbi']->fetchResult("SHOW PLUGINS"); foreach ($plugins as $value) { if ($value['Name'] == 'partition') { $have_partitioning = true; diff --git a/libraries/RecentTable.class.php b/libraries/RecentTable.class.php index 6b3864943d..caaf6b353d 100644 --- a/libraries/RecentTable.class.php +++ b/libraries/RecentTable.class.php @@ -85,7 +85,7 @@ class PMA_RecentTable = " SELECT `tables` FROM " . $this->_pmaTable . " WHERE `username` = '" . $GLOBALS['cfg']['Server']['user'] . "'"; - $row = PMA_DBI_fetchArray(PMA_queryAsControlUser($sql_query)); + $row = $GLOBALS['dbi']->fetchArray(PMA_queryAsControlUser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { @@ -108,13 +108,13 @@ class PMA_RecentTable json_encode($this->tables) ) . "')"; - $success = PMA_DBI_tryQuery($sql_query, $GLOBALS['controllink']); + $success = $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['controllink']); if (! $success) { $message = PMA_Message::error(__('Could not save recent table')); $message->addMessage('<br /><br />'); $message->addMessage( - PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink'])) + PMA_Message::rawError($GLOBALS['dbi']->getError($GLOBALS['controllink'])) ); return $message; } diff --git a/libraries/ServerStatusData.class.php b/libraries/ServerStatusData.class.php index e24ab90f52..17ed188dbf 100644 --- a/libraries/ServerStatusData.class.php +++ b/libraries/ServerStatusData.class.php @@ -57,19 +57,19 @@ class PMA_ServerStatusData /** * get status from server */ - $server_status = PMA_DBI_fetchResult('SHOW GLOBAL STATUS', 0, 1); + $server_status = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL STATUS', 0, 1); if (PMA_DRIZZLE) { // Drizzle doesn't put query statistics into variables, add it $sql = "SELECT concat('Com_', variable_name), variable_value FROM data_dictionary.GLOBAL_STATEMENTS"; - $statements = PMA_DBI_fetchResult($sql, 0, 1); + $statements = $GLOBALS['dbi']->fetchResult($sql, 0, 1); $server_status = array_merge($server_status, $statements); } /** * for some calculations we require also some server settings */ - $server_variables = PMA_DBI_fetchResult('SHOW GLOBAL VARIABLES', 0, 1); + $server_variables = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES', 0, 1); /** * cleanup of some deprecated values @@ -275,7 +275,7 @@ class PMA_ServerStatusData } if (PMA_DRIZZLE) { - $used_queries = PMA_DBI_fetchResult( + $used_queries = $GLOBALS['dbi']->fetchResult( 'SELECT * FROM data_dictionary.global_statements', 0, 1 diff --git a/libraries/StorageEngine.class.php b/libraries/StorageEngine.class.php index ec69871027..972f656c75 100644 --- a/libraries/StorageEngine.class.php +++ b/libraries/StorageEngine.class.php @@ -75,10 +75,10 @@ class PMA_StorageEngine JOIN data_dictionary.modules m USING (module_name) WHERE p.plugin_type = 'StorageEngine' AND p.plugin_name NOT IN ('FunctionEngine', 'schema')"; - $storage_engines = PMA_DBI_fetchResult($sql, 'Engine'); + $storage_engines = $GLOBALS['dbi']->fetchResult($sql, 'Engine'); } else { $storage_engines - = PMA_DBI_fetchResult('SHOW STORAGE ENGINES', 'Engine'); + = $GLOBALS['dbi']->fetchResult('SHOW STORAGE ENGINES', 'Engine'); } } @@ -259,8 +259,8 @@ class PMA_StorageEngine $mysql_vars = array(); $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';'; - $res = PMA_DBI_query($sql_query); - while ($row = PMA_DBI_fetchAssoc($res)) { + $res = $GLOBALS['dbi']->query($sql_query); + while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { if (isset($variables[$row['Variable_name']])) { $mysql_vars[$row['Variable_name']] = $variables[$row['Variable_name']]; } elseif (! $like @@ -279,7 +279,7 @@ class PMA_StorageEngine = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT; } } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); return $mysql_vars; } diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 3e5556863c..33562d3901 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -199,7 +199,7 @@ class PMA_Table } // query information_schema - $result = PMA_DBI_fetchResult( + $result = $GLOBALS['dbi']->fetchResult( "SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "' @@ -222,7 +222,7 @@ class PMA_Table return false; } - $result = PMA_DBI_fetchResult( + $result = $GLOBALS['dbi']->fetchResult( "SELECT TABLE_NAME FROM information_schema.VIEWS WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "' @@ -255,7 +255,7 @@ class PMA_Table $analyzed_sql[0] = array(); $analyzed_sql[0]['create_table_fields'] = array(); - $results = PMA_DBI_fetchResult( + $results = $GLOBALS['dbi']->fetchResult( "SELECT COLUMN_NAME, DATA_TYPE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = '" . PMA_Util::sqlAddSlashes($db) . "' @@ -266,7 +266,7 @@ class PMA_Table = array('type' => strtoupper($result['DATA_TYPE'])); } } else { - $show_create_table = PMA_DBI_fetchValue( + $show_create_table = $GLOBALS['dbi']->fetchValue( 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1 @@ -373,7 +373,7 @@ class PMA_Table } if (! isset(PMA_Table::$cache[$db][$table]) || $force_read) { - PMA_DBI_getTablesFull($db, $table); + $GLOBALS['dbi']->getTablesFull($db, $table); } if (! isset(PMA_Table::$cache[$db][$table])) { @@ -573,7 +573,7 @@ class PMA_Table if (! $force_exact) { if (! isset(PMA_Table::$cache[$db][$table]['Rows']) && ! $is_view) { - $tmp_tables = PMA_DBI_getTablesFull($db, $table); + $tmp_tables = $GLOBALS['dbi']->getTablesFull($db, $table); if (isset($tmp_tables[$table])) { PMA_Table::$cache[$db][$table] = $tmp_tables[$table]; } @@ -592,8 +592,8 @@ class PMA_Table // Make an exception for views in I_S and D_D schema in // Drizzle, as these map to in-memory data and should execute // fast enough - if (! $is_view || (PMA_DRIZZLE && PMA_isSystemSchema($db))) { - $row_count = PMA_DBI_fetchValue( + if (! $is_view || (PMA_DRIZZLE && $GLOBALS['dbi']->isSystemSchema($db))) { + $row_count = $GLOBALS['dbi']->fetchValue( 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) ); @@ -610,16 +610,16 @@ class PMA_Table // so use a LIMIT clause. // Use try_query because it can fail (when a VIEW is // based on a table that no longer exists) - $result = PMA_DBI_tryQuery( + $result = $GLOBALS['dbi']->tryQuery( 'SELECT 1 FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . ' LIMIT ' . $GLOBALS['cfg']['MaxExactCountViews'], null, PMA_DBI_QUERY_STORE ); - if (!PMA_DBI_getError()) { - $row_count = PMA_DBI_numRows($result); - PMA_DBI_freeResult($result); + if (!$GLOBALS['dbi']->getError()) { + $row_count = $GLOBALS['dbi']->numRows($result); + $GLOBALS['dbi']->freeResult($result); } } } @@ -726,7 +726,7 @@ class PMA_Table $table_copy_query, true, PMA_DBI_QUERY_STORE ); - while ($table_copy_row = @PMA_DBI_fetchAssoc($table_copy_rs)) { + while ($table_copy_row = @$GLOBALS['dbi']->fetchAssoc($table_copy_rs)) { $value_parts = array(); foreach ($table_copy_row as $_key => $_val) { if (isset($row_fields[$_key]) && $row_fields[$_key] == 'cc') { @@ -744,10 +744,10 @@ class PMA_Table \'' . implode('\', \'', $new_value_parts) . '\')'; PMA_queryAsControlUser($new_table_query); - $last_id = PMA_DBI_insertId(); + $last_id = $GLOBALS['dbi']->insertId(); } // end while - PMA_DBI_freeResult($table_copy_rs); + $GLOBALS['dbi']->freeResult($table_copy_rs); return $last_id; } @@ -815,7 +815,7 @@ class PMA_Table // Doing a select_db could avoid some problems with replicated databases, // when moving table from replicated one to not replicated one - PMA_DBI_selectDb($target_db); + $GLOBALS['dbi']->selectDb($target_db); $target = PMA_Util::backquote($target_db) . '.' . PMA_Util::backquote($target_table); @@ -859,7 +859,7 @@ class PMA_Table if (PMA_DRIZZLE) { $table_delimiter = 'quote_backtick'; } else { - $server_sql_mode = PMA_DBI_fetchValue( + $server_sql_mode = $GLOBALS['dbi']->fetchValue( "SHOW VARIABLES LIKE 'sql_mode'", 0, 1 @@ -918,7 +918,7 @@ class PMA_Table $drop_query .= ' IF EXISTS ' . PMA_Util::backquote($target_db) . '.' . PMA_Util::backquote($target_table); - PMA_DBI_query($drop_query); + $GLOBALS['dbi']->query($drop_query); $GLOBALS['sql_query'] .= "\n" . $drop_query . ';'; @@ -927,7 +927,7 @@ class PMA_Table $maintain_relations = true; } - @PMA_DBI_query($sql_structure); + @$GLOBALS['dbi']->query($sql_structure); $GLOBALS['sql_query'] .= "\n" . $sql_structure . ';'; if (($move || isset($GLOBALS['add_constraints'])) @@ -971,7 +971,7 @@ class PMA_Table $parsed_sql, 'query_only' ); if ($mode == 'one_table') { - PMA_DBI_query($GLOBALS['sql_constraints_query']); + $GLOBALS['dbi']->query($GLOBALS['sql_constraints_query']); } $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query']; if ($mode == 'one_table') { @@ -987,12 +987,12 @@ class PMA_Table && ! PMA_Table::isView($target_db, $target_table) ) { $sql_set_mode = "SET SQL_MODE='NO_AUTO_VALUE_ON_ZERO'"; - PMA_DBI_query($sql_set_mode); + $GLOBALS['dbi']->query($sql_set_mode); $GLOBALS['sql_query'] .= "\n\n" . $sql_set_mode . ';'; $sql_insert_data = 'INSERT INTO ' . $target . ' SELECT * FROM ' . $source; - PMA_DBI_query($sql_insert_data); + $GLOBALS['dbi']->query($sql_insert_data); $GLOBALS['sql_query'] .= "\n\n" . $sql_insert_data . ';'; } @@ -1003,7 +1003,7 @@ class PMA_Table // This could avoid some problems with replicated databases, when // moving table from replicated one to not replicated one - PMA_DBI_selectDb($source_db); + $GLOBALS['dbi']->selectDb($source_db); if (PMA_Table::isView($source_db, $source_table)) { $sql_drop_query = 'DROP VIEW'; @@ -1011,7 +1011,7 @@ class PMA_Table $sql_drop_query = 'DROP TABLE'; } $sql_drop_query .= ' ' . $source; - PMA_DBI_query($sql_drop_query); + $GLOBALS['dbi']->query($sql_drop_query); // Renable table in configuration storage PMA_REL_renameTable( @@ -1036,7 +1036,7 @@ class PMA_Table $comments_copy_rs = PMA_queryAsControlUser($comments_copy_query); // Write every comment as new copied entry. [MIME] - while ($comments_copy_row = PMA_DBI_fetchAssoc($comments_copy_rs)) { + while ($comments_copy_row = $GLOBALS['dbi']->fetchAssoc($comments_copy_rs)) { $new_comment_query = 'REPLACE INTO ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) . '.' . PMA_Util::backquote($GLOBALS['cfgRelation']['column_info']) . ' (db_name, table_name, column_name, comment' . ($GLOBALS['cfgRelation']['mimework'] ? ', mimetype, transformation, transformation_options' : '') . ') ' . ' VALUES(' @@ -1050,7 +1050,7 @@ class PMA_Table . ')'; PMA_queryAsControlUser($new_comment_query); } // end while - PMA_DBI_freeResult($comments_copy_rs); + $GLOBALS['dbi']->freeResult($comments_copy_rs); unset($comments_copy_rs); } @@ -1248,13 +1248,13 @@ class PMA_Table } // If the table is moved to a different database drop its triggers first - $triggers = PMA_DBI_getTriggers($this->getDbName(), $this->getName(), ''); + $triggers = $GLOBALS['dbi']->getTriggers($this->getDbName(), $this->getName(), ''); $handle_triggers = $this->getDbName() != $new_db && $triggers; if ($handle_triggers) { foreach ($triggers as $trigger) { $sql = 'DROP TRIGGER IF EXISTS ' . PMA_Util::backquote($this->getDbName()) . '.' . PMA_Util::backquote($trigger['name']) . ';'; - PMA_DBI_query($sql); + $GLOBALS['dbi']->query($sql); } } @@ -1265,12 +1265,12 @@ class PMA_Table RENAME TABLE ' . $this->getFullName(true) . ' TO ' . $new_table->getFullName(true) . ';'; // I don't think a specific error message for views is necessary - if (! PMA_DBI_query($GLOBALS['sql_query'])) { + if (! $GLOBALS['dbi']->query($GLOBALS['sql_query'])) { // Restore triggers in the old database if ($handle_triggers) { - PMA_DBI_selectDb($this->getDbName()); + $GLOBALS['dbi']->selectDb($this->getDbName()); foreach ($triggers as $trigger) { - PMA_DBI_query($trigger['create']); + $GLOBALS['dbi']->query($trigger['create']); } } $this->errors[] = sprintf( @@ -1318,12 +1318,12 @@ class PMA_Table */ public function getUniqueColumns($backquoted = true) { - $sql = PMA_DBI_getTableIndexesSql( + $sql = $GLOBALS['dbi']->getTableIndexesSql( $this->getDbName(), $this->getName(), 'Non_unique = 0' ); - $uniques = PMA_DBI_fetchResult( + $uniques = $GLOBALS['dbi']->fetchResult( $sql, array('Key_name', null), 'Column_name' @@ -1355,12 +1355,12 @@ class PMA_Table */ public function getIndexedColumns($backquoted = true) { - $sql = PMA_DBI_getTableIndexesSql( + $sql = $GLOBALS['dbi']->getTableIndexesSql( $this->getDbName(), $this->getName(), 'Seq_in_index = 1' ); - $indexed = PMA_DBI_fetchResult($sql, 'Column_name', 'Column_name'); + $indexed = $GLOBALS['dbi']->fetchResult($sql, 'Column_name', 'Column_name'); $return = array(); foreach ($indexed as $column) { @@ -1383,7 +1383,7 @@ class PMA_Table public function getColumns($backquoted = true) { $sql = 'SHOW COLUMNS FROM ' . $this->getFullName(true); - $indexed = PMA_DBI_fetchResult($sql, 'Field', 'Field'); + $indexed = $GLOBALS['dbi']->fetchResult($sql, 'Field', 'Field'); $return = array(); foreach ($indexed as $column) { @@ -1410,7 +1410,7 @@ class PMA_Table . " AND `db_name` = '" . PMA_Util::sqlAddSlashes($this->db_name) . "'" . " AND `table_name` = '" . PMA_Util::sqlAddSlashes($this->name) . "'"; - $row = PMA_DBI_fetchArray(PMA_queryAsControlUser($sql_query)); + $row = $GLOBALS['dbi']->fetchArray(PMA_queryAsControlUser($sql_query)); if (isset($row[0])) { return json_decode($row[0], true); } else { @@ -1434,13 +1434,13 @@ class PMA_Table . "', '" . PMA_Util::sqlAddSlashes($this->name) . "', '" . PMA_Util::sqlAddSlashes(json_encode($this->uiprefs)) . "', NULL)"; - $success = PMA_DBI_tryQuery($sql_query, $GLOBALS['controllink']); + $success = $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['controllink']); if (!$success) { $message = PMA_Message::error(__('Could not save table UI preferences')); $message->addMessage('<br /><br />'); $message->addMessage( - PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink'])) + PMA_Message::rawError($GLOBALS['dbi']->getError($GLOBALS['controllink'])) ); return $message; } @@ -1448,7 +1448,7 @@ class PMA_Table // Remove some old rows in table_uiprefs if it exceeds the configured // maximum rows $sql_query = 'SELECT COUNT(*) FROM ' . $pma_table; - $rows_count = PMA_DBI_fetchValue($sql_query); + $rows_count = $GLOBALS['dbi']->fetchValue($sql_query); $max_rows = $GLOBALS['cfg']['Server']['MaxTableUiprefs']; if ($rows_count > $max_rows) { $num_rows_to_delete = $rows_count - $max_rows; @@ -1456,7 +1456,7 @@ class PMA_Table = ' DELETE FROM ' . $pma_table . ' ORDER BY last_update ASC' . ' LIMIT ' . $num_rows_to_delete; - $success = PMA_DBI_tryQuery($sql_query, $GLOBALS['controllink']); + $success = $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['controllink']); if (!$success) { $message = PMA_Message::error( @@ -1467,7 +1467,7 @@ class PMA_Table ); $message->addMessage('<br /><br />'); $message->addMessage( - PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink'])) + PMA_Message::rawError($GLOBALS['dbi']->getError($GLOBALS['controllink'])) ); print_r($message); return $message; diff --git a/libraries/TableSearch.class.php b/libraries/TableSearch.class.php index 918a557260..69e5393e1f 100644 --- a/libraries/TableSearch.class.php +++ b/libraries/TableSearch.class.php @@ -123,7 +123,7 @@ class PMA_TableSearch private function _loadTableInfo() { // Gets the list and number of columns - $columns = PMA_DBI_getColumns($this->_db, $this->_table, null, true); + $columns = $GLOBALS['dbi']->getColumns($this->_db, $this->_table, null, true); // Get details about the geometry fucntions $geom_types = PMA_Util::getGISDatatypes(); diff --git a/libraries/Tracker.class.php b/libraries/Tracker.class.php index 32a9cd8e59..7eab3ee78c 100644 --- a/libraries/Tracker.class.php +++ b/libraries/Tracker.class.php @@ -213,7 +213,7 @@ class PMA_Tracker " AND table_name = '" . PMA_Util::sqlAddSlashes($tablename) . "' " . " ORDER BY version DESC"; - $row = PMA_DBI_fetchArray(PMA_queryAsControlUser($sql_query)); + $row = $GLOBALS['dbi']->fetchArray(PMA_queryAsControlUser($sql_query)); if (isset($row['tracking_active']) && $row['tracking_active'] == 1) { return true; @@ -275,7 +275,7 @@ class PMA_Tracker // Get data definition snapshot of table - $columns = PMA_DBI_getColumns($dbname, $tablename, null, true); + $columns = $GLOBALS['dbi']->getColumns($dbname, $tablename, null, true); // int indices to reduce size $columns = array_values($columns); // remove Privileges to reduce size @@ -283,7 +283,7 @@ class PMA_Tracker unset($columns[$i]['Privileges']); } - $indexes = PMA_DBI_getTableIndexes($dbname, $tablename); + $indexes = $GLOBALS['dbi']->getTableIndexes($dbname, $tablename); $snapshot = array('COLUMNS' => $columns, 'INDEXES' => $indexes); $snapshot = serialize($snapshot); @@ -560,7 +560,7 @@ class PMA_Tracker ? ' AND tracking & ' . self::_transformTrackingSet($statement) . ' <> 0' : " AND FIND_IN_SET('" . $statement . "',tracking) > 0" ; } - $row = PMA_DBI_fetchArray(PMA_queryAsControlUser($sql_query)); + $row = $GLOBALS['dbi']->fetchArray(PMA_queryAsControlUser($sql_query)); return isset($row[0]) ? $row[0] : -1; @@ -592,7 +592,7 @@ class PMA_Tracker $sql_query .= " AND `version` = '" . PMA_Util::sqlAddSlashes($version) ."' ". " ORDER BY `version` DESC LIMIT 1"; - $mixed = PMA_DBI_fetchAssoc(PMA_queryAsControlUser($sql_query)); + $mixed = $GLOBALS['dbi']->fetchAssoc(PMA_queryAsControlUser($sql_query)); // Parse log $log_schema_entries = explode('# log ', $mixed['schema_sql']); diff --git a/libraries/Types.class.php b/libraries/Types.class.php index d41e7995e0..d3579ea457 100644 --- a/libraries/Types.class.php +++ b/libraries/Types.class.php @@ -832,7 +832,7 @@ class PMA_Types_Drizzle extends PMA_Types WHERE plugin_name IN ('" . implode("','", $functions) . "') AND plugin_type = 'Function' AND is_active"; - $drizzle_functions = PMA_DBI_fetchResult($sql, 'f', 'f'); + $drizzle_functions = $GLOBALS['dbi']->fetchResult($sql, 'f', 'f'); if (count($drizzle_functions) > 0) { $ret = array_merge($ret, $drizzle_functions); sort($ret); diff --git a/libraries/Util.class.php b/libraries/Util.class.php index 1ee1272661..ff42ccb40d 100644 --- a/libraries/Util.class.php +++ b/libraries/Util.class.php @@ -633,7 +633,7 @@ class PMA_Util $error_msg = ''; if (! $error_message) { - $error_message = PMA_DBI_getError(); + $error_message = $GLOBALS['dbi']->getError(); } if (! $the_query && ! empty($GLOBALS['sql_query'])) { $the_query = $GLOBALS['sql_query']; @@ -791,7 +791,7 @@ class PMA_Util $sep = $GLOBALS['cfg']['NavigationTreeTableSeparator']; if ($tables === null) { - $tables = PMA_DBI_getTablesFull( + $tables = $GLOBALS['dbi']->getTablesFull( $db, false, false, null, $limit_offset, $limit_count ); if ($GLOBALS['cfg']['NaturalOrder']) { @@ -826,7 +826,7 @@ class PMA_Util // set this because PMA_Table::countRecords() can use it $tbl_is_view = $table['TABLE_TYPE'] == 'VIEW'; - if ($tbl_is_view || PMA_isSystemSchema($db)) { + if ($tbl_is_view || $GLOBALS['dbi']->isSystemSchema($db)) { $table['Rows'] = PMA_Table::countRecords( $db, $table['Name'], @@ -1397,7 +1397,7 @@ class PMA_Util // and do not set a constant as we might be switching servers if (defined('PMA_MYSQL_INT_VERSION') && (PMA_MYSQL_INT_VERSION >= 50037) - && PMA_DBI_fetchValue("SHOW VARIABLES LIKE 'profiling'") + && $GLOBALS['dbi']->fetchValue("SHOW VARIABLES LIKE 'profiling'") ) { self::cacheSet('profiling_supported', true, true); } else { @@ -2181,7 +2181,7 @@ class PMA_Util $condition = ''; $con_key = ''; $con_val = ''; - $field_flags = PMA_DBI_fieldFlags($handle, $i); + $field_flags = $GLOBALS['dbi']->fieldFlags($handle, $i); $meta = $fields_meta[$i]; // do not use a column alias in a condition @@ -3174,15 +3174,15 @@ class PMA_Util $wktsql .= ", SRID(x'" . $hex . "')"; } - $wktresult = PMA_DBI_tryQuery($wktsql, null, PMA_DBI_QUERY_STORE); - $wktarr = PMA_DBI_fetchRow($wktresult, 0); + $wktresult = $GLOBALS['dbi']->tryQuery($wktsql, null, PMA_DBI_QUERY_STORE); + $wktarr = $GLOBALS['dbi']->fetchRow($wktresult, 0); $wktval = $wktarr[0]; if ($includeSRID) { $srid = $wktarr[1]; $wktval = "'" . $wktval . "'," . $srid; } - @PMA_DBI_freeResult($wktresult); + @$GLOBALS['dbi']->freeResult($wktresult); return $wktval; } @@ -3312,7 +3312,7 @@ class PMA_Util /* Fetch columns list if required */ if (strpos($string, '@COLUMNS@') !== false) { - $columns_list = PMA_DBI_getColumns($GLOBALS['db'], $GLOBALS['table']); + $columns_list = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']); // sometimes the table no longer exists at this point if (! is_null($columns_list)) { @@ -3851,7 +3851,7 @@ class PMA_Util { // Get the username for the current user in the format // required to use in the information schema database. - $user = PMA_DBI_fetchValue("SELECT CURRENT_USER();"); + $user = $GLOBALS['dbi']->fetchValue("SELECT CURRENT_USER();"); if ($user === false) { return false; } @@ -3868,7 +3868,7 @@ class PMA_Util . "WHERE GRANTEE='%s' AND PRIVILEGE_TYPE='%s'"; // Check global privileges first. - $user_privileges = PMA_DBI_fetchValue( + $user_privileges = $GLOBALS['dbi']->fetchValue( sprintf( $query, 'USER_PRIVILEGES', @@ -3885,7 +3885,7 @@ class PMA_Util // need to escape wildcards in db and table names, see bug #3518484 $db = str_replace(array('%', '_'), array('\%', '\_'), $db); $query .= " AND TABLE_SCHEMA='%s'"; - $schema_privileges = PMA_DBI_fetchValue( + $schema_privileges = $GLOBALS['dbi']->fetchValue( sprintf( $query, 'SCHEMA_PRIVILEGES', @@ -3908,7 +3908,7 @@ class PMA_Util // need to escape wildcards in db and table names, see bug #3518484 $tbl = str_replace(array('%', '_'), array('\%', '\_'), $tbl); $query .= " AND TABLE_NAME='%s'"; - $table_privileges = PMA_DBI_fetchValue( + $table_privileges = $GLOBALS['dbi']->fetchValue( sprintf( $query, 'TABLE_PRIVILEGES', diff --git a/libraries/bookmark.lib.php b/libraries/bookmark.lib.php index 0f669c5a30..6b1a0091fe 100644 --- a/libraries/bookmark.lib.php +++ b/libraries/bookmark.lib.php @@ -65,7 +65,7 @@ function PMA_Bookmark_getList($db) . ' WHERE dbase = \'' . PMA_Util::sqlAddSlashes($db) . '\'' . ' AND user = \'' . PMA_Util::sqlAddSlashes($cfgBookmark['user']) . '\'' . ' ORDER BY label'; - $per_user = PMA_DBI_fetchResult( + $per_user = $GLOBALS['dbi']->fetchResult( $query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE ); @@ -74,7 +74,7 @@ function PMA_Bookmark_getList($db) . ' WHERE dbase = \'' . PMA_Util::sqlAddSlashes($db) . '\'' . ' AND user = \'\'' . ' ORDER BY label'; - $global = PMA_DBI_fetchResult( + $global = $GLOBALS['dbi']->fetchResult( $query, 'id', 'label', $controllink, PMA_DBI_QUERY_STORE ); @@ -132,7 +132,7 @@ function PMA_Bookmark_get($db, $id, $id_field = 'id', $action_bookmark_all = fal $query .= ' AND ' . PMA_Util::backquote($id_field) . ' = ' . $id; - return PMA_DBI_fetchValue($query, 0, 0, $controllink); + return $GLOBALS['dbi']->fetchValue($query, 0, 0, $controllink); } // end of the 'PMA_Bookmark_get()' function /** @@ -165,7 +165,7 @@ function PMA_Bookmark_save($fields, $all_users = false) . '\'' . ($all_users ? '' : PMA_Util::sqlAddSlashes($fields['user'])) . '\', ' . '\'' . PMA_Util::sqlAddSlashes(urldecode($fields['query'])) . '\', ' . '\'' . PMA_Util::sqlAddSlashes($fields['label']) . '\')'; - return PMA_DBI_query($query, $controllink); + return $GLOBALS['dbi']->query($query, $controllink); } // end of the 'PMA_Bookmark_save()' function @@ -196,7 +196,7 @@ function PMA_Bookmark_delete($db, $id) . ' WHERE (user = \'' . PMA_Util::sqlAddSlashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')' . ' AND id = ' . $id; - return PMA_DBI_tryQuery($query, $controllink); + return $GLOBALS['dbi']->tryQuery($query, $controllink); } // end of the 'PMA_Bookmark_delete()' function diff --git a/libraries/build_html_for_db.lib.php b/libraries/build_html_for_db.lib.php index 93bc473f32..360a220d0b 100644 --- a/libraries/build_html_for_db.lib.php +++ b/libraries/build_html_for_db.lib.php @@ -81,7 +81,7 @@ function PMA_buildHtmlForDb( . 'title="' . htmlspecialchars($current['SCHEMA_NAME']) . '" ' . 'value="' . htmlspecialchars($current['SCHEMA_NAME']) . '"'; - if (PMA_isSystemSchema($current['SCHEMA_NAME'], true)) { + if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) { $out .= ' disabled="disabled"'; } $out .= ' /></td>'; diff --git a/libraries/check_user_privileges.lib.php b/libraries/check_user_privileges.lib.php index e90914511a..a7a20b97f3 100644 --- a/libraries/check_user_privileges.lib.php +++ b/libraries/check_user_privileges.lib.php @@ -12,7 +12,7 @@ if (! defined('PHPMYADMIN')) { /** * */ -$GLOBALS['is_superuser'] = PMA_isSuperuser(); +$GLOBALS['is_superuser'] = $GLOBALS['dbi']->isSuperuser(); /** * sets privilege information extracted from SHOW GRANTS result @@ -51,7 +51,7 @@ function PMA_analyseShowGrant() $GLOBALS['db_to_create'] = ''; $GLOBALS['dbs_where_create_table_allowed'] = array(); - $rs_usr = PMA_DBI_tryQuery('SHOW GRANTS'); + $rs_usr = $GLOBALS['dbi']->tryQuery('SHOW GRANTS'); if (! $rs_usr) { return; @@ -60,7 +60,7 @@ function PMA_analyseShowGrant() $re0 = '(^|(\\\\\\\\)+|[^\\\\])'; // non-escaped wildcards $re1 = '(^|[^\\\\])(\\\)+'; // escaped wildcards - while ($row = PMA_DBI_fetchRow($rs_usr)) { + while ($row = $GLOBALS['dbi']->fetchRow($rs_usr)) { // extract db from GRANT ... ON *.* or GRANT ... ON db.* $db_name_offset = strpos($row[0], ' ON ') + 4; $show_grants_dbname = substr( @@ -107,8 +107,8 @@ function PMA_analyseShowGrant() // does this db exist? if ((preg_match('/' . $re0 . '%|_/', $show_grants_dbname) && ! preg_match('/\\\\%|\\\\_/', $show_grants_dbname)) - || (! PMA_DBI_tryQuery('USE ' . preg_replace('/' . $re1 . '(%|_)/', '\\1\\3', $dbname_to_test)) - && substr(PMA_DBI_getError(), 1, 4) != 1044) + || (! $GLOBALS['dbi']->tryQuery('USE ' . preg_replace('/' . $re1 . '(%|_)/', '\\1\\3', $dbname_to_test)) + && substr($GLOBALS['dbi']->getError(), 1, 4) != 1044) ) { /** * Do not handle the underscore wildcard @@ -135,7 +135,7 @@ function PMA_analyseShowGrant() } // end if } // end while - PMA_DBI_freeResult($rs_usr); + $GLOBALS['dbi']->freeResult($rs_usr); // must also cacheUnset() them in // libraries/plugins/auth/AuthenticationCookie.class.php diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 8e58f22c03..dc43b21728 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -816,7 +816,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { /** * Loads the proper database interface for this server */ - include_once './libraries/database_interface.lib.php'; + include_once './libraries/DatabaseInterface.class.php'; include_once './libraries/logging.lib.php'; @@ -951,14 +951,14 @@ if (! defined('PMA_MINIMUM_COMMON')) { // otherwise we leave the $server_details['port'] unset, // allowing it to take default mysql port - $controllink = PMA_DBI_connect( + $controllink = $GLOBALS['dbi']->connect( $cfg['Server']['controluser'], $cfg['Server']['controlpass'], true, $server_details ); } else { - $controllink = PMA_DBI_connect( + $controllink = $GLOBALS['dbi']->connect( $cfg['Server']['controluser'], $cfg['Server']['controlpass'], true @@ -967,7 +967,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { } // Connects to the server (validates user's login) - $userlink = PMA_DBI_connect( + $userlink = $GLOBALS['dbi']->connect( $cfg['Server']['user'], $cfg['Server']['password'], false ); @@ -1141,7 +1141,7 @@ unset($dummy); // here, the function does not exist with this configuration: // $cfg['ServerDefault'] = 0; -$GLOBALS['is_superuser'] = function_exists('PMA_isSuperuser') && PMA_isSuperuser(); +$GLOBALS['is_superuser'] = function_exists('PMA_isSuperuser') && $GLOBALS['dbi']->isSuperuser(); if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { /** diff --git a/libraries/core.lib.php b/libraries/core.lib.php index 9ca9ad22fb..1e162e74c3 100644 --- a/libraries/core.lib.php +++ b/libraries/core.lib.php @@ -323,13 +323,13 @@ function PMA_warnMissingExtension($extension, $fatal = false, $extra = '') */ function PMA_getTableCount($db) { - $tables = PMA_DBI_tryQuery( + $tables = $GLOBALS['dbi']->tryQuery( 'SHOW TABLES FROM ' . PMA_Util::backquote($db) . ';', null, PMA_DBI_QUERY_STORE ); if ($tables) { - $num_tables = PMA_DBI_numRows($tables); - PMA_DBI_freeResult($tables); + $num_tables = $GLOBALS['dbi']->numRows($tables); + $GLOBALS['dbi']->freeResult($tables); } else { $num_tables = 0; } diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php deleted file mode 100644 index be2e99bc06..0000000000 --- a/libraries/database_interface.lib.php +++ /dev/null @@ -1,2389 +0,0 @@ -<?php -/* vim: set expandtab sw=4 ts=4 sts=4: */ -/** - * Common Option Constants For DBI Functions - * - * @package PhpMyAdmin-DBI - */ -if (! defined('PHPMYADMIN')) { - exit; -} - -/** - * Force STORE_RESULT method, ignored by classic MySQL. - */ -define('PMA_DBI_QUERY_STORE', 1); -/** - * Do not read whole query. - */ -define('PMA_DBI_QUERY_UNBUFFERED', 2); -/** - * Get session variable. - */ -define('PMA_DBI_GETVAR_SESSION', 1); -/** - * Get global variable. - */ -define('PMA_DBI_GETVAR_GLOBAL', 2); - -/** - * Checks whether database extension is loaded - * - * @param string $extension mysql extension to check - * - * @return bool - */ -function PMA_DBI_checkDbExtension($extension = 'mysql') -{ - if ($extension == 'drizzle' && function_exists('drizzle_create')) { - return true; - } else if (function_exists($extension . '_connect')) { - return true; - } - - return false; -} - -if (defined('TESTSUITE')) { - /** - * For testsuite we use dummy driver which can fake some queries. - */ - include_once './libraries/dbi/DBIDummy.class.php'; - $GLOBALS['extension'] = new PMA_DBI_Dummy(); -} else { - - /** - * check for requested extension - */ - if (! PMA_DBI_checkDbExtension($GLOBALS['cfg']['Server']['extension'])) { - - // if it fails try alternative extension ... - // and display an error ... - - /** - * @todo add different messages for alternative extension - * and complete fail (no alternative extension too) - */ - PMA_warnMissingExtension( - $GLOBALS['cfg']['Server']['extension'], - false, - PMA_Util::showDocu('faq', 'faqmysql') - ); - - if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') { - $alternativ_extension = 'mysqli'; - } else { - $alternativ_extension = 'mysql'; - } - - if (! PMA_DBI_checkDbExtension($alternativ_extension)) { - // if alternative fails too ... - PMA_warnMissingExtension( - $GLOBALS['cfg']['Server']['extension'], - true, - PMA_Util::showDocu('faq', 'faqmysql') - ); - } - - $GLOBALS['cfg']['Server']['extension'] = $alternativ_extension; - unset($alternativ_extension); - } - - /** - * Including The DBI Plugin - */ - switch($GLOBALS['cfg']['Server']['extension']) { - case 'mysql' : - include_once './libraries/dbi/DBIMysql.class.php'; - $GLOBALS['extension'] = new PMA_DBI_Mysql(); - break; - case 'mysqli' : - include_once './libraries/dbi/DBIMysqli.class.php'; - $GLOBALS['extension'] = new PMA_DBI_Mysqli(); - break; - case 'drizzle' : - include_once './libraries/dbi/DBIDrizzle.class.php'; - $GLOBALS['extension'] = new PMA_DBI_Drizzle(); - break; - } -} - -/** - * runs a query - * - * @param string $query SQL query to execte - * @param mixed $link optional database link to use - * @param int $options optional query options - * @param bool $cache_affected_rows whether to cache affected rows - * - * @return mixed - */ -function PMA_DBI_query($query, $link = null, $options = 0, - $cache_affected_rows = true -) { - $res = PMA_DBI_tryQuery($query, $link, $options, $cache_affected_rows) - or PMA_Util::mysqlDie(PMA_DBI_getError($link), $query); - return $res; -} - -/** - * Stores query data into session data for debugging purposes - * - * @param string $query Query text - * @param resource $link database link - * @param resource $result Query result - * @param integer $time Time to execute query - * - * @return void - */ -function PMA_DBI_DBG_query($query, $link, $result, $time) -{ - $hash = md5($query); - - if (isset($_SESSION['debug']['queries'][$hash])) { - $_SESSION['debug']['queries'][$hash]['count']++; - } else { - $_SESSION['debug']['queries'][$hash] = array(); - if ($result == false) { - $_SESSION['debug']['queries'][$hash]['error'] - = '<b style="color:red">' . mysqli_error($link) . '</b>'; - } - $_SESSION['debug']['queries'][$hash]['count'] = 1; - $_SESSION['debug']['queries'][$hash]['query'] = $query; - $_SESSION['debug']['queries'][$hash]['time'] = $time; - } - - $trace = array(); - foreach (debug_backtrace() as $trace_step) { - $trace[] - = (isset($trace_step['file']) - ? PMA_Error::relPath($trace_step['file']) - : '') - . (isset($trace_step['line']) - ? '#' . $trace_step['line'] . ': ' - : '') - . (isset($trace_step['class']) ? $trace_step['class'] : '') - . (isset($trace_step['type']) ? $trace_step['type'] : '') - . (isset($trace_step['function']) ? $trace_step['function'] : '') - . '(' - . (isset($trace_step['params']) - ? implode(', ', $trace_step['params']) - : '' - ) - . ')' - ; - } - $_SESSION['debug']['queries'][$hash]['trace'][] = $trace; -} - -/** - * runs a query and returns the result - * - * @param string $query query to run - * @param resource $link mysql link resource - * @param integer $options query options - * @param bool $cache_affected_rows whether to cache affected row - * - * @return mixed - */ -function PMA_DBI_tryQuery($query, $link = null, $options = 0, - $cache_affected_rows = true -) { - if (empty($link)) { - if (isset($GLOBALS['userlink'])) { - $link = $GLOBALS['userlink']; - } else { - return false; - } - } - - if ($GLOBALS['cfg']['DBG']['sql']) { - $time = microtime(true); - } - - $result = $GLOBALS['extension']->realQuery($query, $link, $options); - - if ($cache_affected_rows) { - $GLOBALS['cached_affected_rows'] = PMA_DBI_affectedRows($link, false); - } - - if ($GLOBALS['cfg']['DBG']['sql']) { - $time = microtime(true) - $time; - PMA_DBI_DBG_query($query, $link, $result, $time); - } - if ($result != false && PMA_Tracker::isActive() == true ) { - PMA_Tracker::handleQuery($query); - } - - return $result; -} - -/** - * Run multi query statement and return results - * - * @param string $multi_query multi query statement to execute - * @param mysqli $link mysqli object - * - * @return mysqli_result collection | boolean(false) - */ -function PMA_DBI_tryMultiQuery($multi_query = '', $link = null) -{ - - if (empty($link)) { - if (isset($GLOBALS['userlink'])) { - $link = $GLOBALS['userlink']; - } else { - return false; - } - } - - return $GLOBALS['extension']->realMultiQuery($link, $multi_query); - -} - -/** - * converts charset of a mysql message, usually coming from mysql_error(), - * into PMA charset, usally UTF-8 - * uses language to charset mapping from mysql/share/errmsg.txt - * and charset names to ISO charset from information_schema.CHARACTER_SETS - * - * @param string $message the message - * - * @return string $message - */ -function PMA_DBI_convertMessage($message) -{ - // latin always last! - $encodings = array( - 'japanese' => 'EUC-JP', //'ujis', - 'japanese-sjis' => 'Shift-JIS', //'sjis', - 'korean' => 'EUC-KR', //'euckr', - 'russian' => 'KOI8-R', //'koi8r', - 'ukrainian' => 'KOI8-U', //'koi8u', - 'greek' => 'ISO-8859-7', //'greek', - 'serbian' => 'CP1250', //'cp1250', - 'estonian' => 'ISO-8859-13', //'latin7', - 'slovak' => 'ISO-8859-2', //'latin2', - 'czech' => 'ISO-8859-2', //'latin2', - 'hungarian' => 'ISO-8859-2', //'latin2', - 'polish' => 'ISO-8859-2', //'latin2', - 'romanian' => 'ISO-8859-2', //'latin2', - 'spanish' => 'CP1252', //'latin1', - 'swedish' => 'CP1252', //'latin1', - 'italian' => 'CP1252', //'latin1', - 'norwegian-ny' => 'CP1252', //'latin1', - 'norwegian' => 'CP1252', //'latin1', - 'portuguese' => 'CP1252', //'latin1', - 'danish' => 'CP1252', //'latin1', - 'dutch' => 'CP1252', //'latin1', - 'english' => 'CP1252', //'latin1', - 'french' => 'CP1252', //'latin1', - 'german' => 'CP1252', //'latin1', - ); - - $server_language = PMA_DBI_fetchValue( - 'SHOW VARIABLES LIKE \'language\';', - 0, - 1 - ); - if ($server_language) { - $found = array(); - $match = preg_match( - '&(?:\\\|\\/)([^\\\\\/]*)(?:\\\|\\/)$&i', - $server_language, - $found - ); - if ($match) { - $server_language = $found[1]; - } - } - - if (! empty($server_language) && isset($encodings[$server_language])) { - $encoding = $encodings[$server_language]; - } else { - /* Fallback to CP1252 if we can not detect */ - $encoding = 'CP1252'; - } - - if (function_exists('iconv')) { - if ((@stristr(PHP_OS, 'AIX')) - && (@strcasecmp(ICONV_IMPL, 'unknown') == 0) - && (@strcasecmp(ICONV_VERSION, 'unknown') == 0) - ) { - include_once './libraries/iconv_wrapper.lib.php'; - $message = PMA_aix_iconv_wrapper( - $encoding, - 'utf-8' . $GLOBALS['cfg']['IconvExtraParams'], - $message - ); - } else { - $message = iconv( - $encoding, - 'utf-8' . $GLOBALS['cfg']['IconvExtraParams'], - $message - ); - } - } elseif (function_exists('recode_string')) { - $message = recode_string( - $encoding . '..' . 'utf-8', - $message - ); - } elseif (function_exists('libiconv')) { - $message = libiconv($encoding, 'utf-8', $message); - } elseif (function_exists('mb_convert_encoding')) { - // do not try unsupported charsets - if (! in_array($server_language, array('ukrainian', 'greek', 'serbian'))) { - $message = mb_convert_encoding( - $message, - 'utf-8', - $encoding - ); - } - } - - return $message; -} - -/** - * returns array with table names for given db - * - * @param string $database name of database - * @param mixed $link mysql link resource|object - * - * @return array tables names - */ -function PMA_DBI_getTables($database, $link = null) -{ - return PMA_DBI_fetchResult( - 'SHOW TABLES FROM ' . PMA_Util::backquote($database) . ';', - null, - 0, - $link, - PMA_DBI_QUERY_STORE - ); -} - -/** - * usort comparison callback - * - * @param string $a first argument to sort - * @param string $b second argument to sort - * - * @return integer a value representing whether $a should be before $b in the - * sorted array or not - * - * @access private - */ -function PMA_usortComparisonCallback($a, $b) -{ - if ($GLOBALS['cfg']['NaturalOrder']) { - $sorter = 'strnatcasecmp'; - } else { - $sorter = 'strcasecmp'; - } - /* No sorting when key is not present */ - if (! isset($a[$GLOBALS['callback_sort_by']]) - || ! isset($b[$GLOBALS['callback_sort_by']]) - ) { - return 0; - } - // produces f.e.: - // return -1 * strnatcasecmp($a["SCHEMA_TABLES"], $b["SCHEMA_TABLES"]) - return ($GLOBALS['callback_sort_order'] == 'ASC' ? 1 : -1) * $sorter( - $a[$GLOBALS['callback_sort_by']], $b[$GLOBALS['callback_sort_by']] - ); -} // end of the 'PMA_usortComparisonCallback()' function - -/** - * returns array of all tables in given db or dbs - * this function expects unquoted names: - * RIGHT: my_database - * WRONG: `my_database` - * WRONG: my\_database - * if $tbl_is_group is true, $table is used as filter for table names - * if $tbl_is_group is 'comment, $table is used as filter for table comments - * - * <code> - * PMA_DBI_getTablesFull('my_database'); - * PMA_DBI_getTablesFull('my_database', 'my_table')); - * PMA_DBI_getTablesFull('my_database', 'my_tables_', true)); - * PMA_DBI_getTablesFull('my_database', 'my_tables_', 'comment')); - * </code> - * - * @param string $database database - * @param string|bool $table table or false - * @param boolean|string $tbl_is_group $table is a table group - * @param mixed $link mysql link - * @param integer $limit_offset zero-based offset for the count - * @param boolean|integer $limit_count number of tables to return - * @param string $sort_by table attribute to sort by - * @param string $sort_order direction to sort (ASC or DESC) - * - * @todo move into PMA_Table - * - * @return array list of tables in given db(s) - */ -function PMA_DBI_getTablesFull($database, $table = false, - $tbl_is_group = false, $link = null, $limit_offset = 0, - $limit_count = false, $sort_by = 'Name', $sort_order = 'ASC' -) { - if (true === $limit_count) { - $limit_count = $GLOBALS['cfg']['MaxTableList']; - } - // prepare and check parameters - if (! is_array($database)) { - $databases = array($database); - } else { - $databases = $database; - } - - $tables = array(); - - if (! $GLOBALS['cfg']['Server']['DisableIS']) { - // get table information from information_schema - if ($table) { - if (true === $tbl_is_group) { - $sql_where_table = 'AND t.`TABLE_NAME` LIKE \'' - . PMA_Util::escapeMysqlWildcards(PMA_Util::sqlAddSlashes($table)) - . '%\''; - } elseif ('comment' === $tbl_is_group) { - $sql_where_table = 'AND t.`TABLE_COMMENT` LIKE \'' - . PMA_Util::escapeMysqlWildcards(PMA_Util::sqlAddSlashes($table)) - . '%\''; - } else { - $sql_where_table = 'AND t.`TABLE_NAME` = \'' - . PMA_Util::sqlAddSlashes($table) . '\''; - } - } else { - $sql_where_table = ''; - } - - // for PMA bc: - // `SCHEMA_FIELD_NAME` AS `SHOW_TABLE_STATUS_FIELD_NAME` - // - // on non-Windows servers, - // added BINARY in the WHERE clause to force a case sensitive - // comparison (if we are looking for the db Aa we don't want - // to find the db aa) - $this_databases = array_map('PMA_Util::sqlAddSlashes', $databases); - - if (PMA_DRIZZLE) { - $engine_info = PMA_Util::cacheGet('drizzle_engines', true); - $stats_join = "LEFT JOIN (SELECT 0 NUM_ROWS) AS stat ON false"; - if (isset($engine_info['InnoDB']) - && $engine_info['InnoDB']['module_library'] == 'innobase' - ) { - $stats_join = "LEFT JOIN data_dictionary.INNODB_SYS_TABLESTATS stat" - . " ON (t.ENGINE = 'InnoDB' AND stat.NAME" - . " = (t.TABLE_SCHEMA || '/') || t.TABLE_NAME)"; - } - - // data_dictionary.table_cache may not contain any data for some tables, - // it's just a table cache - // auto_increment == 0 is cast to NULL because currently (2011.03.13 GA) - // Drizzle doesn't provide correct value - $sql = " - SELECT t.*, - t.TABLE_SCHEMA AS `Db`, - t.TABLE_NAME AS `Name`, - t.TABLE_TYPE AS `TABLE_TYPE`, - t.ENGINE AS `Engine`, - t.ENGINE AS `Type`, - t.TABLE_VERSION AS `Version`,-- VERSION - t.ROW_FORMAT AS `Row_format`, - coalesce(tc.ROWS, stat.NUM_ROWS) - AS `Rows`,-- TABLE_ROWS, - coalesce(tc.ROWS, stat.NUM_ROWS) - AS `TABLE_ROWS`, - tc.AVG_ROW_LENGTH AS `Avg_row_length`, -- AVG_ROW_LENGTH - tc.TABLE_SIZE AS `Data_length`, -- DATA_LENGTH - NULL AS `Max_data_length`, -- MAX_DATA_LENGTH - NULL AS `Index_length`, -- INDEX_LENGTH - NULL AS `Data_free`, -- DATA_FREE - nullif(t.AUTO_INCREMENT, 0) - AS `Auto_increment`, - t.TABLE_CREATION_TIME AS `Create_time`, -- CREATE_TIME - t.TABLE_UPDATE_TIME AS `Update_time`, -- UPDATE_TIME - NULL AS `Check_time`, -- CHECK_TIME - t.TABLE_COLLATION AS `Collation`, - NULL AS `Checksum`, -- CHECKSUM - NULL AS `Create_options`, -- CREATE_OPTIONS - t.TABLE_COMMENT AS `Comment` - FROM data_dictionary.TABLES t - LEFT JOIN data_dictionary.TABLE_CACHE tc - ON tc.TABLE_SCHEMA = t.TABLE_SCHEMA AND tc.TABLE_NAME - = t.TABLE_NAME - $stats_join - WHERE t.TABLE_SCHEMA IN ('" . implode("', '", $this_databases) . "') - " . $sql_where_table; - } else { - $sql = ' - SELECT *, - `TABLE_SCHEMA` AS `Db`, - `TABLE_NAME` AS `Name`, - `TABLE_TYPE` AS `TABLE_TYPE`, - `ENGINE` AS `Engine`, - `ENGINE` AS `Type`, - `VERSION` AS `Version`, - `ROW_FORMAT` AS `Row_format`, - `TABLE_ROWS` AS `Rows`, - `AVG_ROW_LENGTH` AS `Avg_row_length`, - `DATA_LENGTH` AS `Data_length`, - `MAX_DATA_LENGTH` AS `Max_data_length`, - `INDEX_LENGTH` AS `Index_length`, - `DATA_FREE` AS `Data_free`, - `AUTO_INCREMENT` AS `Auto_increment`, - `CREATE_TIME` AS `Create_time`, - `UPDATE_TIME` AS `Update_time`, - `CHECK_TIME` AS `Check_time`, - `TABLE_COLLATION` AS `Collation`, - `CHECKSUM` AS `Checksum`, - `CREATE_OPTIONS` AS `Create_options`, - `TABLE_COMMENT` AS `Comment` - FROM `information_schema`.`TABLES` t - WHERE ' . (PMA_IS_WINDOWS ? '' : 'BINARY') . ' `TABLE_SCHEMA` - IN (\'' . implode("', '", $this_databases) . '\') - ' . $sql_where_table; - } - - // Sort the tables - $sql .= " ORDER BY $sort_by $sort_order"; - - if ($limit_count) { - $sql .= ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset; - } - - $tables = PMA_DBI_fetchResult( - $sql, array('TABLE_SCHEMA', 'TABLE_NAME'), null, $link - ); - unset($sql_where_table, $sql); - - if (PMA_DRIZZLE) { - // correct I_S and D_D names returned by D_D.TABLES - - // Drizzle generally uses lower case for them, - // but TABLES returns uppercase - foreach ((array)$database as $db) { - $db_upper = strtoupper($db); - if (!isset($tables[$db]) && isset($tables[$db_upper])) { - $tables[$db] = $tables[$db_upper]; - unset($tables[$db_upper]); - } - } - } - - if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) { - // here, the array's first key is by schema name - foreach ($tables as $one_database_name => $one_database_tables) { - uksort($one_database_tables, 'strnatcasecmp'); - - if ($sort_order == 'DESC') { - $one_database_tables = array_reverse($one_database_tables); - } - $tables[$one_database_name] = $one_database_tables; - } - } - } // end (get information from table schema) - - // If permissions are wrong on even one database directory, - // information_schema does not return any table info for any database - // this is why we fall back to SHOW TABLE STATUS even for MySQL >= 50002 - if (empty($tables) && !PMA_DRIZZLE) { - foreach ($databases as $each_database) { - if ($table || (true === $tbl_is_group)) { - $sql = 'SHOW TABLE STATUS FROM ' - . PMA_Util::backquote($each_database) - .' LIKE \'' - . PMA_Util::escapeMysqlWildcards( - PMA_Util::sqlAddSlashes($table, true) - ) - . '%\''; - } else { - $sql = 'SHOW TABLE STATUS FROM ' - . PMA_Util::backquote($each_database); - } - - $useStatusCache = false; - - if (extension_loaded('apc') - && isset($GLOBALS['cfg']['Server']['StatusCacheDatabases']) - && ! empty($GLOBALS['cfg']['Server']['StatusCacheLifetime']) - ) { - $statusCacheDatabases - = (array) $GLOBALS['cfg']['Server']['StatusCacheDatabases']; - if (in_array($each_database, $statusCacheDatabases)) { - $useStatusCache = true; - } - } - - $each_tables = null; - - if ($useStatusCache) { - $cacheKey = 'phpMyAdmin_tableStatus_' - . sha1($GLOBALS['cfg']['Server']['host'] . '_' . $sql); - - $each_tables = apc_fetch($cacheKey); - } - - if (! $each_tables) { - $each_tables = PMA_DBI_fetchResult($sql, 'Name', null, $link); - } - - if ($useStatusCache) { - apc_store( - $cacheKey, $each_tables, - $GLOBALS['cfg']['Server']['StatusCacheLifetime'] - ); - } - - // Sort naturally if the config allows it and we're sorting - // the Name column. - if ($sort_by == 'Name' && $GLOBALS['cfg']['NaturalOrder']) { - uksort($each_tables, 'strnatcasecmp'); - - if ($sort_order == 'DESC') { - $each_tables = array_reverse($each_tables); - } - } else { - // Prepare to sort by creating array of the selected sort - // value to pass to array_multisort - - // Size = Data_length + Index_length - if ($sort_by == 'Data_length') { - foreach ($each_tables as $table_name => $table_data) { - ${$sort_by}[$table_name] = strtolower( - $table_data['Data_length'] + $table_data['Index_length'] - ); - } - } else { - foreach ($each_tables as $table_name => $table_data) { - ${$sort_by}[$table_name] = strtolower($table_data[$sort_by]); - } - } - - if ($sort_order == 'DESC') { - array_multisort($$sort_by, SORT_DESC, $each_tables); - } else { - array_multisort($$sort_by, SORT_ASC, $each_tables); - } - - // cleanup the temporary sort array - unset($$sort_by); - } - - if ($limit_count) { - $each_tables = array_slice( - $each_tables, $limit_offset, $limit_count - ); - } - - foreach ($each_tables as $table_name => $each_table) { - if ('comment' === $tbl_is_group - && 0 === strpos($each_table['Comment'], $table) - ) { - // remove table from list - unset($each_tables[$table_name]); - continue; - } - - if (! isset($each_tables[$table_name]['Type']) - && isset($each_tables[$table_name]['Engine']) - ) { - // pma BC, same parts of PMA still uses 'Type' - $each_tables[$table_name]['Type'] - =& $each_tables[$table_name]['Engine']; - } elseif (! isset($each_tables[$table_name]['Engine']) - && isset($each_tables[$table_name]['Type'])) { - // old MySQL reports Type, newer MySQL reports Engine - $each_tables[$table_name]['Engine'] - =& $each_tables[$table_name]['Type']; - } - - // MySQL forward compatibility - // so pma could use this array as if every server is of version >5.0 - // todo : remove and check usage in the rest of the code, - // MySQL 5.0 is required by current PMA version - $each_tables[$table_name]['TABLE_SCHEMA'] = $each_database; - $each_tables[$table_name]['TABLE_NAME'] - =& $each_tables[$table_name]['Name']; - $each_tables[$table_name]['ENGINE'] - =& $each_tables[$table_name]['Engine']; - $each_tables[$table_name]['VERSION'] - =& $each_tables[$table_name]['Version']; - $each_tables[$table_name]['ROW_FORMAT'] - =& $each_tables[$table_name]['Row_format']; - $each_tables[$table_name]['TABLE_ROWS'] - =& $each_tables[$table_name]['Rows']; - $each_tables[$table_name]['AVG_ROW_LENGTH'] - =& $each_tables[$table_name]['Avg_row_length']; - $each_tables[$table_name]['DATA_LENGTH'] - =& $each_tables[$table_name]['Data_length']; - $each_tables[$table_name]['MAX_DATA_LENGTH'] - =& $each_tables[$table_name]['Max_data_length']; - $each_tables[$table_name]['INDEX_LENGTH'] - =& $each_tables[$table_name]['Index_length']; - $each_tables[$table_name]['DATA_FREE'] - =& $each_tables[$table_name]['Data_free']; - $each_tables[$table_name]['AUTO_INCREMENT'] - =& $each_tables[$table_name]['Auto_increment']; - $each_tables[$table_name]['CREATE_TIME'] - =& $each_tables[$table_name]['Create_time']; - $each_tables[$table_name]['UPDATE_TIME'] - =& $each_tables[$table_name]['Update_time']; - $each_tables[$table_name]['CHECK_TIME'] - =& $each_tables[$table_name]['Check_time']; - $each_tables[$table_name]['TABLE_COLLATION'] - =& $each_tables[$table_name]['Collation']; - $each_tables[$table_name]['CHECKSUM'] - =& $each_tables[$table_name]['Checksum']; - $each_tables[$table_name]['CREATE_OPTIONS'] - =& $each_tables[$table_name]['Create_options']; - $each_tables[$table_name]['TABLE_COMMENT'] - =& $each_tables[$table_name]['Comment']; - - if (strtoupper($each_tables[$table_name]['Comment']) === 'VIEW' - && $each_tables[$table_name]['Engine'] == null - ) { - $each_tables[$table_name]['TABLE_TYPE'] = 'VIEW'; - } else { - /** - * @todo difference between 'TEMPORARY' and 'BASE TABLE' - * but how to detect? - */ - $each_tables[$table_name]['TABLE_TYPE'] = 'BASE TABLE'; - } - } - - $tables[$each_database] = $each_tables; - } - } - - // cache table data - // so PMA_Table does not require to issue SHOW TABLE STATUS again - // Note: I don't see why we would need array_merge_recursive() here, - // as it creates double entries for the same table (for example a double - // entry for Comment when changing the storage engine in Operations) - // Note 2: Instead of array_merge(), simply use the + operator because - // array_merge() renumbers numeric keys starting with 0, therefore - // we would lose a db name thats consists only of numbers - foreach ($tables as $one_database => $its_tables) { - if (isset(PMA_Table::$cache[$one_database])) { - PMA_Table::$cache[$one_database] - = PMA_Table::$cache[$one_database] + $tables[$one_database]; - } else { - PMA_Table::$cache[$one_database] = $tables[$one_database]; - } - } - unset($one_database, $its_tables); - - if (! is_array($database)) { - if (isset($tables[$database])) { - return $tables[$database]; - } elseif (isset($tables[strtolower($database)])) { - // on windows with lower_case_table_names = 1 - // MySQL returns - // with SHOW DATABASES or information_schema.SCHEMATA: `Test` - // but information_schema.TABLES gives `test` - // bug #2036 - // https://sourceforge.net/p/phpmyadmin/bugs/2036/ - return $tables[strtolower($database)]; - } else { - // one database but inexact letter case match - // as Drizzle is always case insensitive, - // we can safely return the only result - if (PMA_DRIZZLE && count($tables) == 1) { - $keys = array_keys($tables); - if (strlen(array_pop($keys)) == strlen($database)) { - return array_pop($tables); - } - } - return $tables; - } - } else { - return $tables; - } -} - - -/** - * Get VIEWs in a particular database - * - * @param string $db Database name to look in - * - * @return array $views Set of VIEWs inside the database - */ -function PMA_DBI_getVirtualTables($db) -{ - - $tables_full = PMA_DBI_getTablesFull($db); - $views = array(); - - foreach ($tables_full as $table=>$tmp) { - - if (PMA_Table::isView($db, $table)) { - $views[] = $table; - } - - } - - return $views; - -} - - -/** - * returns array with databases containing extended infos about them - * - * @param string $database database - * @param boolean $force_stats retrieve stats also for MySQL < 5 - * @param resource $link mysql link - * @param string $sort_by column to order by - * @param string $sort_order ASC or DESC - * @param integer $limit_offset starting offset for LIMIT - * @param bool|int $limit_count row count for LIMIT or true - * for $GLOBALS['cfg']['MaxDbList'] - * - * @todo move into PMA_List_Database? - * - * @return array $databases - */ -function PMA_DBI_getDatabasesFull($database = null, $force_stats = false, - $link = null, $sort_by = 'SCHEMA_NAME', $sort_order = 'ASC', - $limit_offset = 0, $limit_count = false -) { - $sort_order = strtoupper($sort_order); - - if (true === $limit_count) { - $limit_count = $GLOBALS['cfg']['MaxDbList']; - } - - // initialize to avoid errors when there are no databases - $databases = array(); - - $apply_limit_and_order_manual = true; - - if (! $GLOBALS['cfg']['Server']['DisableIS']) { - /** - * if $GLOBALS['cfg']['NaturalOrder'] is enabled, we cannot use LIMIT - * cause MySQL does not support natural ordering, we have to do it afterward - */ - $limit = ''; - if (! $GLOBALS['cfg']['NaturalOrder']) { - if ($limit_count) { - $limit = ' LIMIT ' . $limit_count . ' OFFSET ' . $limit_offset; - } - - $apply_limit_and_order_manual = false; - } - - // get table information from information_schema - if ($database) { - $sql_where_schema = 'WHERE `SCHEMA_NAME` LIKE \'' - . PMA_Util::sqlAddSlashes($database) . '\''; - } else { - $sql_where_schema = ''; - } - - if (PMA_DRIZZLE) { - // data_dictionary.table_cache may not contain any data for some - // tables, it's just a table cache - $sql = 'SELECT - s.SCHEMA_NAME, - s.DEFAULT_COLLATION_NAME'; - if ($force_stats) { - // no TABLE_CACHE data, stable results are better than - // constantly changing - $sql .= ', - COUNT(t.TABLE_SCHEMA) AS SCHEMA_TABLES, - SUM(stat.NUM_ROWS) AS SCHEMA_TABLE_ROWS'; - } - $sql .= ' - FROM data_dictionary.SCHEMAS s'; - if ($force_stats) { - $engine_info = PMA_Util::cacheGet('drizzle_engines', true); - $stats_join = "LEFT JOIN (SELECT 0 NUM_ROWS) AS stat ON false"; - if (isset($engine_info['InnoDB']) - && $engine_info['InnoDB']['module_library'] == 'innobase' - ) { - $stats_join = "LEFT JOIN data_dictionary.INNODB_SYS_TABLESTATS" - . " stat ON (t.ENGINE = 'InnoDB' AND stat.NAME" - . " = (t.TABLE_SCHEMA || '/') || t.TABLE_NAME)"; - } - - $sql .= " - LEFT JOIN data_dictionary.TABLES t - ON t.TABLE_SCHEMA = s.SCHEMA_NAME - $stats_join"; - } - $sql .= $sql_where_schema . ' - GROUP BY s.SCHEMA_NAME - ORDER BY ' . PMA_Util::backquote($sort_by) . ' ' . $sort_order - . $limit; - } else { - $sql = 'SELECT - s.SCHEMA_NAME, - s.DEFAULT_COLLATION_NAME'; - if ($force_stats) { - $sql .= ', - COUNT(t.TABLE_SCHEMA) AS SCHEMA_TABLES, - SUM(t.TABLE_ROWS) AS SCHEMA_TABLE_ROWS, - SUM(t.DATA_LENGTH) AS SCHEMA_DATA_LENGTH, - SUM(t.MAX_DATA_LENGTH) AS SCHEMA_MAX_DATA_LENGTH, - SUM(t.INDEX_LENGTH) AS SCHEMA_INDEX_LENGTH, - SUM(t.DATA_LENGTH + t.INDEX_LENGTH) - AS SCHEMA_LENGTH, - SUM(t.DATA_FREE) AS SCHEMA_DATA_FREE'; - } - $sql .= ' - FROM `information_schema`.SCHEMATA s'; - if ($force_stats) { - $sql .= ' - LEFT JOIN `information_schema`.TABLES t - ON BINARY t.TABLE_SCHEMA = BINARY s.SCHEMA_NAME'; - } - $sql .= $sql_where_schema . ' - GROUP BY BINARY s.SCHEMA_NAME - ORDER BY BINARY ' . PMA_Util::backquote($sort_by) - . ' ' . $sort_order - . $limit; - } - - $databases = PMA_DBI_fetchResult($sql, 'SCHEMA_NAME', null, $link); - - $mysql_error = PMA_DBI_getError($link); - if (! count($databases) && $GLOBALS['errno']) { - PMA_Util::mysqlDie($mysql_error, $sql); - } - - // display only databases also in official database list - // f.e. to apply hide_db and only_db - $drops = array_diff( - array_keys($databases), (array) $GLOBALS['pma']->databases - ); - if (count($drops)) { - foreach ($drops as $drop) { - unset($databases[$drop]); - } - unset($drop); - } - unset($sql_where_schema, $sql, $drops); - } else { - foreach ($GLOBALS['pma']->databases as $database_name) { - // MySQL forward compatibility - // so pma could use this array as if every server is of version >5.0 - // todo : remove and check the rest of the code for usage, - // MySQL 5.0 or higher is required for current PMA version - $databases[$database_name]['SCHEMA_NAME'] = $database_name; - - if ($force_stats) { - include_once './libraries/mysql_charsets.lib.php'; - - $databases[$database_name]['DEFAULT_COLLATION_NAME'] - = PMA_getDbCollation($database_name); - - // get additional info about tables - $databases[$database_name]['SCHEMA_TABLES'] = 0; - $databases[$database_name]['SCHEMA_TABLE_ROWS'] = 0; - $databases[$database_name]['SCHEMA_DATA_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_INDEX_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_LENGTH'] = 0; - $databases[$database_name]['SCHEMA_DATA_FREE'] = 0; - - $res = PMA_DBI_query( - 'SHOW TABLE STATUS FROM ' - . PMA_Util::backquote($database_name) . ';' - ); - - while ($row = PMA_DBI_fetchAssoc($res)) { - $databases[$database_name]['SCHEMA_TABLES']++; - $databases[$database_name]['SCHEMA_TABLE_ROWS'] - += $row['Rows']; - $databases[$database_name]['SCHEMA_DATA_LENGTH'] - += $row['Data_length']; - $databases[$database_name]['SCHEMA_MAX_DATA_LENGTH'] - += $row['Max_data_length']; - $databases[$database_name]['SCHEMA_INDEX_LENGTH'] - += $row['Index_length']; - - // for InnoDB, this does not contain the number of - // overhead bytes but the total free space - if ('InnoDB' != $row['Engine']) { - $databases[$database_name]['SCHEMA_DATA_FREE'] - += $row['Data_free']; - } - $databases[$database_name]['SCHEMA_LENGTH'] - += $row['Data_length'] + $row['Index_length']; - } - PMA_DBI_freeResult($res); - unset($res); - } - } - } - - - /** - * apply limit and order manually now - * (caused by older MySQL < 5 or $GLOBALS['cfg']['NaturalOrder']) - */ - if ($apply_limit_and_order_manual) { - $GLOBALS['callback_sort_order'] = $sort_order; - $GLOBALS['callback_sort_by'] = $sort_by; - usort($databases, 'PMA_usortComparisonCallback'); - unset($GLOBALS['callback_sort_order'], $GLOBALS['callback_sort_by']); - - /** - * now apply limit - */ - if ($limit_count) { - $databases = array_slice($databases, $limit_offset, $limit_count); - } - } - - return $databases; -} - -/** - * returns detailed array with all columns for given table in database, - * or all tables/databases - * - * @param string $database name of database - * @param string $table name of table to retrieve columns from - * @param string $column name of specific column - * @param mixed $link mysql link resource - * - * @return array - */ -function PMA_DBI_getColumnsFull($database = null, $table = null, - $column = null, $link = null -) { - $columns = array(); - - if (! $GLOBALS['cfg']['Server']['DisableIS']) { - $sql_wheres = array(); - $array_keys = array(); - - // get columns information from information_schema - if (null !== $database) { - $sql_wheres[] = '`TABLE_SCHEMA` = \'' - . PMA_Util::sqlAddSlashes($database) . '\' '; - } else { - $array_keys[] = 'TABLE_SCHEMA'; - } - if (null !== $table) { - $sql_wheres[] = '`TABLE_NAME` = \'' - . PMA_Util::sqlAddSlashes($table) . '\' '; - } else { - $array_keys[] = 'TABLE_NAME'; - } - if (null !== $column) { - $sql_wheres[] = '`COLUMN_NAME` = \'' - . PMA_Util::sqlAddSlashes($column) . '\' '; - } else { - $array_keys[] = 'COLUMN_NAME'; - } - - // for PMA bc: - // `[SCHEMA_FIELD_NAME]` AS `[SHOW_FULL_COLUMNS_FIELD_NAME]` - if (PMA_DRIZZLE) { - $sql = "SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, - column_name AS `Field`, - (CASE - WHEN character_maximum_length > 0 - THEN concat(lower(data_type), '(', character_maximum_length, ')') - WHEN numeric_precision > 0 OR numeric_scale > 0 - THEN concat(lower(data_type), '(', numeric_precision, - ',', numeric_scale, ')') - WHEN enum_values IS NOT NULL - THEN concat(lower(data_type), '(', enum_values, ')') - ELSE lower(data_type) END) - AS `Type`, - collation_name AS `Collation`, - (CASE is_nullable - WHEN 1 THEN 'YES' - ELSE 'NO' END) AS `Null`, - (CASE - WHEN is_used_in_primary THEN 'PRI' - ELSE '' END) AS `Key`, - column_default AS `Default`, - (CASE - WHEN is_auto_increment THEN 'auto_increment' - WHEN column_default_update - THEN 'on update ' || column_default_update - ELSE '' END) AS `Extra`, - NULL AS `Privileges`, - column_comment AS `Comment` - FROM data_dictionary.columns"; - } else { - $sql = ' - SELECT *, - `COLUMN_NAME` AS `Field`, - `COLUMN_TYPE` AS `Type`, - `COLLATION_NAME` AS `Collation`, - `IS_NULLABLE` AS `Null`, - `COLUMN_KEY` AS `Key`, - `COLUMN_DEFAULT` AS `Default`, - `EXTRA` AS `Extra`, - `PRIVILEGES` AS `Privileges`, - `COLUMN_COMMENT` AS `Comment` - FROM `information_schema`.`COLUMNS`'; - } - if (count($sql_wheres)) { - $sql .= "\n" . ' WHERE ' . implode(' AND ', $sql_wheres); - } - - $columns = PMA_DBI_fetchResult($sql, $array_keys, null, $link); - unset($sql_wheres, $sql); - } else { - if (null === $database) { - foreach ($GLOBALS['pma']->databases as $database) { - $columns[$database] = PMA_DBI_getColumnsFull( - $database, null, null, $link - ); - } - return $columns; - } elseif (null === $table) { - $tables = PMA_DBI_getTables($database); - foreach ($tables as $table) { - $columns[$table] = PMA_DBI_getColumnsFull( - $database, $table, null, $link - ); - } - return $columns; - } - - $sql = 'SHOW FULL COLUMNS FROM ' - . PMA_Util::backquote($database) . '.' . PMA_Util::backquote($table); - if (null !== $column) { - $sql .= " LIKE '" . PMA_Util::sqlAddSlashes($column, true) . "'"; - } - - $columns = PMA_DBI_fetchResult($sql, 'Field', null, $link); - } - $ordinal_position = 1; - foreach ($columns as $column_name => $each_column) { - - // MySQL forward compatibility - // so pma could use this array as if every server is of version >5.0 - // todo : remove and check the rest of the code for usage, - // MySQL 5.0 or higher is required for current PMA version - $columns[$column_name]['COLUMN_NAME'] =& $columns[$column_name]['Field']; - $columns[$column_name]['COLUMN_TYPE'] =& $columns[$column_name]['Type']; - $columns[$column_name]['COLLATION_NAME'] - =& $columns[$column_name]['Collation']; - $columns[$column_name]['IS_NULLABLE'] =& $columns[$column_name]['Null']; - $columns[$column_name]['COLUMN_KEY'] =& $columns[$column_name]['Key']; - $columns[$column_name]['COLUMN_DEFAULT'] - =& $columns[$column_name]['Default']; - $columns[$column_name]['EXTRA'] - =& $columns[$column_name]['Extra']; - $columns[$column_name]['PRIVILEGES'] - =& $columns[$column_name]['Privileges']; - $columns[$column_name]['COLUMN_COMMENT'] - =& $columns[$column_name]['Comment']; - - $columns[$column_name]['TABLE_CATALOG'] = null; - $columns[$column_name]['TABLE_SCHEMA'] = $database; - $columns[$column_name]['TABLE_NAME'] = $table; - $columns[$column_name]['ORDINAL_POSITION'] = $ordinal_position; - $columns[$column_name]['DATA_TYPE'] - = substr( - $columns[$column_name]['COLUMN_TYPE'], - 0, - strpos($columns[$column_name]['COLUMN_TYPE'], '(') - ); - /** - * @todo guess CHARACTER_MAXIMUM_LENGTH from COLUMN_TYPE - */ - $columns[$column_name]['CHARACTER_MAXIMUM_LENGTH'] = null; - /** - * @todo guess CHARACTER_OCTET_LENGTH from CHARACTER_MAXIMUM_LENGTH - */ - $columns[$column_name]['CHARACTER_OCTET_LENGTH'] = null; - $columns[$column_name]['NUMERIC_PRECISION'] = null; - $columns[$column_name]['NUMERIC_SCALE'] = null; - $columns[$column_name]['CHARACTER_SET_NAME'] - = substr( - $columns[$column_name]['COLLATION_NAME'], - 0, - strpos($columns[$column_name]['COLLATION_NAME'], '_') - ); - - $ordinal_position++; - } - - if (null !== $column) { - reset($columns); - $columns = current($columns); - } - - return $columns; -} - -/** - * Returns SQL query for fetching columns for a table - * - * The 'Key' column is not calculated properly, use PMA_DBI_getColumns() to get - * correct values. - * - * @param string $database name of database - * @param string $table name of table to retrieve columns from - * @param string $column name of column, null to show all columns - * @param boolean $full whether to return full info or only column names - * - * @see PMA_DBI_getColumns() - * - * @return string - */ -function PMA_DBI_getColumnsSql($database, $table, $column = null, $full = false) -{ - if (PMA_DRIZZLE) { - // `Key` column: - // * used in primary key => PRI - // * unique one-column => UNI - // * indexed, one-column or first in multi-column => MUL - // Promotion of UNI to PRI in case no promary index exists - // is done after query is executed - $sql = "SELECT - column_name AS `Field`, - (CASE - WHEN character_maximum_length > 0 - THEN concat(lower(data_type), '(', character_maximum_length, ')') - WHEN numeric_precision > 0 OR numeric_scale > 0 - THEN concat(lower(data_type), '(', numeric_precision, - ',', numeric_scale, ')') - WHEN enum_values IS NOT NULL - THEN concat(lower(data_type), '(', enum_values, ')') - ELSE lower(data_type) END) - AS `Type`, - " . ($full ? " - collation_name AS `Collation`," : '') . " - (CASE is_nullable - WHEN 1 THEN 'YES' - ELSE 'NO' END) AS `Null`, - (CASE - WHEN is_used_in_primary THEN 'PRI' - WHEN is_unique AND NOT is_multi THEN 'UNI' - WHEN is_indexed - AND (NOT is_multi OR is_first_in_multi) THEN 'MUL' - ELSE '' END) AS `Key`, - column_default AS `Default`, - (CASE - WHEN is_auto_increment THEN 'auto_increment' - WHEN column_default_update <> '' - THEN 'on update ' || column_default_update - ELSE '' END) AS `Extra` - " . ($full ? " , - NULL AS `Privileges`, - column_comment AS `Comment`" : '') . " - FROM data_dictionary.columns - WHERE table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' - AND table_name = '" . PMA_Util::sqlAddSlashes($table) . "' - " . (($column != null) ? " - AND column_name = '" . PMA_Util::sqlAddSlashes($column) . "'" : ''); - // ORDER BY ordinal_position - } else { - $sql = 'SHOW ' . ($full ? 'FULL' : '') . ' COLUMNS FROM ' - . PMA_Util::backquote($database) . '.' . PMA_Util::backquote($table) - . (($column != null) ? "LIKE '" - . PMA_Util::sqlAddSlashes($column, true) . "'" : ''); - } - return $sql; -} - -/** - * Returns descriptions of columns in given table (all or given by $column) - * - * @param string $database name of database - * @param string $table name of table to retrieve columns from - * @param string $column name of column, null to show all columns - * @param boolean $full whether to return full info or only column names - * @param mixed $link mysql link resource - * - * @return false|array array indexed by column names or, - * if $column is given, flat array description - */ -function PMA_DBI_getColumns($database, $table, $column = null, $full = false, - $link = null -) { - $sql = PMA_DBI_getColumnsSql($database, $table, $column, $full); - $fields = PMA_DBI_fetchResult($sql, 'Field', null, $link); - if (! is_array($fields) || count($fields) == 0) { - return null; - } - if (PMA_DRIZZLE) { - // fix Key column, it's much simpler in PHP than in SQL - $has_pk = false; - $has_pk_candidates = false; - foreach ($fields as $f) { - if ($f['Key'] == 'PRI') { - $has_pk = true; - break; - } else if ($f['Null'] == 'NO' - && ($f['Key'] == 'MUL' - || $f['Key'] == 'UNI') - ) { - $has_pk_candidates = true; - } - } - if (! $has_pk && $has_pk_candidates) { - // check whether we can promote some unique index to PRI - $sql = " - SELECT i.index_name, p.column_name - FROM data_dictionary.indexes i - JOIN data_dictionary.index_parts p - USING (table_schema, table_name) - WHERE i.table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' - AND i.table_name = '" . PMA_Util::sqlAddSlashes($table) . "' - AND i.is_unique - AND NOT i.is_nullable"; - $fs = PMA_DBI_fetchResult($sql, 'index_name', null, $link); - $fs = $fs ? array_shift($fs) : array(); - foreach ($fs as $f) { - $fields[$f]['Key'] = 'PRI'; - } - } - } - - return ($column != null) ? array_shift($fields) : $fields; -} - -/** - * Returns all column names in given table - * - * @param string $database name of database - * @param string $table name of table to retrieve columns from - * @param mixed $link mysql link resource - * - * @return null|array - */ -function PMA_DBI_getColumnNames($database, $table, $link = null) -{ - $sql = PMA_DBI_getColumnsSql($database, $table); - // We only need the 'Field' column which contains the table's column names - $fields = array_keys(PMA_DBI_fetchResult($sql, 'Field', null, $link)); - - if ( ! is_array($fields) || count($fields) == 0 ) { - return null; - } - return $fields; -} - -/** -* Returns SQL for fetching information on table indexes (SHOW INDEXES) -* -* @param string $database name of database -* @param string $table name of the table whose indexes are to be retreived -* @param string $where additional conditions for WHERE -* -* @return array $indexes -*/ -function PMA_DBI_getTableIndexesSql($database, $table, $where = null) -{ - if (PMA_DRIZZLE) { - $sql = "SELECT - ip.table_name AS `Table`, - (NOT ip.is_unique) AS Non_unique, - ip.index_name AS Key_name, - ip.sequence_in_index+1 AS Seq_in_index, - ip.column_name AS Column_name, - (CASE - WHEN i.index_type = 'BTREE' THEN 'A' - ELSE NULL END) AS Collation, - NULL AS Cardinality, - compare_length AS Sub_part, - NULL AS Packed, - ip.is_nullable AS `Null`, - i.index_type AS Index_type, - NULL AS Comment, - i.index_comment AS Index_comment - FROM data_dictionary.index_parts ip - LEFT JOIN data_dictionary.indexes i - USING (table_schema, table_name, index_name) - WHERE table_schema = '" . PMA_Util::sqlAddSlashes($database) . "' - AND table_name = '" . PMA_Util::sqlAddSlashes($table) . "' - "; - } else { - $sql = 'SHOW INDEXES FROM ' . PMA_Util::backquote($database) . '.' - . PMA_Util::backquote($table); - } - if ($where) { - $sql .= (PMA_DRIZZLE ? ' AND (' : ' WHERE (') . $where . ')'; - } - return $sql; -} - -/** -* Returns indexes of a table -* -* @param string $database name of database -* @param string $table name of the table whose indexes are to be retrieved -* @param mixed $link mysql link resource -* -* @return array $indexes -*/ -function PMA_DBI_getTableIndexes($database, $table, $link = null) -{ - $sql = PMA_DBI_getTableIndexesSql($database, $table); - $indexes = PMA_DBI_fetchResult($sql, null, null, $link); - - if (! is_array($indexes) || count($indexes) < 1) { - return array(); - } - return $indexes; -} - -/** - * returns value of given mysql server variable - * - * @param string $var mysql server variable name - * @param int $type PMA_DBI_GETVAR_SESSION|PMA_DBI_GETVAR_GLOBAL - * @param mixed $link mysql link resource|object - * - * @return mixed value for mysql server variable - */ -function PMA_DBI_getVariable($var, $type = PMA_DBI_GETVAR_SESSION, $link = null) -{ - if ($link === null) { - if (isset($GLOBALS['userlink'])) { - $link = $GLOBALS['userlink']; - } else { - return false; - } - } - - switch ($type) { - case PMA_DBI_GETVAR_SESSION: - $modifier = ' SESSION'; - break; - case PMA_DBI_GETVAR_GLOBAL: - $modifier = ' GLOBAL'; - break; - default: - $modifier = ''; - } - return PMA_DBI_fetchValue( - 'SHOW' . $modifier . ' VARIABLES LIKE \'' . $var . '\';', 0, 1, $link - ); -} - -/** - * Function called just after a connection to the MySQL database server has - * been established. It sets the connection collation, and determins the - * version of MySQL which is running. - * - * @param mixed $link mysql link resource|object - * @param boolean $is_controluser whether link is for control user - * - * @return void - */ -function PMA_DBI_postConnect($link, $is_controluser = false) -{ - if (! defined('PMA_MYSQL_INT_VERSION')) { - if (PMA_Util::cacheExists('PMA_MYSQL_INT_VERSION', true)) { - define( - 'PMA_MYSQL_INT_VERSION', - PMA_Util::cacheGet('PMA_MYSQL_INT_VERSION', true) - ); - define( - 'PMA_MYSQL_MAJOR_VERSION', - PMA_Util::cacheGet('PMA_MYSQL_MAJOR_VERSION', true) - ); - define( - 'PMA_MYSQL_STR_VERSION', - PMA_Util::cacheGet('PMA_MYSQL_STR_VERSION', true) - ); - define( - 'PMA_MYSQL_VERSION_COMMENT', - PMA_Util::cacheGet('PMA_MYSQL_VERSION_COMMENT', true) - ); - } else { - $version = PMA_DBI_fetchSingleRow( - 'SELECT @@version, @@version_comment', - 'ASSOC', - $link - ); - - if ($version) { - $match = explode('.', $version['@@version']); - define('PMA_MYSQL_MAJOR_VERSION', (int)$match[0]); - define( - 'PMA_MYSQL_INT_VERSION', - (int) sprintf( - '%d%02d%02d', $match[0], $match[1], intval($match[2]) - ) - ); - define('PMA_MYSQL_STR_VERSION', $version['@@version']); - define('PMA_MYSQL_VERSION_COMMENT', $version['@@version_comment']); - } else { - define('PMA_MYSQL_INT_VERSION', 50015); - define('PMA_MYSQL_MAJOR_VERSION', 5); - define('PMA_MYSQL_STR_VERSION', '5.00.15'); - define('PMA_MYSQL_VERSION_COMMENT', ''); - } - PMA_Util::cacheSet( - 'PMA_MYSQL_INT_VERSION', - PMA_MYSQL_INT_VERSION, - true - ); - PMA_Util::cacheSet( - 'PMA_MYSQL_MAJOR_VERSION', - PMA_MYSQL_MAJOR_VERSION, - true - ); - PMA_Util::cacheSet( - 'PMA_MYSQL_STR_VERSION', - PMA_MYSQL_STR_VERSION, - true - ); - PMA_Util::cacheSet( - 'PMA_MYSQL_VERSION_COMMENT', - PMA_MYSQL_VERSION_COMMENT, - true - ); - } - // detect Drizzle by version number: - // <year>.<month>.<build number>(.<patch rev) - define('PMA_DRIZZLE', PMA_MYSQL_MAJOR_VERSION >= 2009); - } - - // Skip charsets for Drizzle - if (!PMA_DRIZZLE) { - if (! empty($GLOBALS['collation_connection'])) { - PMA_DBI_query("SET CHARACTER SET 'utf8';", $link, PMA_DBI_QUERY_STORE); - $set_collation_con_query = "SET collation_connection = '" - . PMA_Util::sqlAddSlashes($GLOBALS['collation_connection']) . "';"; - PMA_DBI_query( - $set_collation_con_query, - $link, - PMA_DBI_QUERY_STORE - ); - } else { - PMA_DBI_query( - "SET NAMES 'utf8' COLLATE 'utf8_general_ci';", - $link, - PMA_DBI_QUERY_STORE - ); - } - } - - // Cache plugin list for Drizzle - if (PMA_DRIZZLE && !PMA_Util::cacheExists('drizzle_engines', true)) { - $sql = "SELECT p.plugin_name, m.module_library - FROM data_dictionary.plugins p - JOIN data_dictionary.modules m USING (module_name) - WHERE p.plugin_type = 'StorageEngine' - AND p.plugin_name NOT IN ('FunctionEngine', 'schema') - AND p.is_active = 'YES'"; - $engines = PMA_DBI_fetchResult($sql, 'plugin_name', null, $link); - PMA_Util::cacheSet('drizzle_engines', $engines, true); - } -} - -/** - * returns a single value from the given result or query, - * if the query or the result has more than one row or field - * the first field of the first row is returned - * - * <code> - * $sql = 'SELECT `name` FROM `user` WHERE `id` = 123'; - * $user_name = PMA_DBI_fetchValue($sql); - * // produces - * // $user_name = 'John Doe' - * </code> - * - * @param string|mysql_result $result query or mysql result - * @param integer $row_number row to fetch the value from, - * starting at 0, with 0 being default - * @param integer|string $field field to fetch the value from, - * starting at 0, with 0 being default - * @param resource $link mysql link - * - * @return mixed value of first field in first row from result - * or false if not found - */ -function PMA_DBI_fetchValue($result, $row_number = 0, $field = 0, $link = null) -{ - $value = false; - - if (is_string($result)) { - $result = PMA_DBI_tryQuery($result, $link, PMA_DBI_QUERY_STORE, false); - } - - // return false if result is empty or false - // or requested row is larger than rows in result - if (PMA_DBI_numRows($result) < ($row_number + 1)) { - return $value; - } - - // if $field is an integer use non associative mysql fetch function - if (is_int($field)) { - $fetch_function = 'PMA_DBI_fetchRow'; - } else { - $fetch_function = 'PMA_DBI_fetchAssoc'; - } - - // get requested row - for ($i = 0; $i <= $row_number; $i++) { - $row = $fetch_function($result); - } - PMA_DBI_freeResult($result); - - // return requested field - if (isset($row[$field])) { - $value = $row[$field]; - } - unset($row); - - return $value; -} - -/** - * returns only the first row from the result - * - * <code> - * $sql = 'SELECT * FROM `user` WHERE `id` = 123'; - * $user = PMA_DBI_fetchSingleRow($sql); - * // produces - * // $user = array('id' => 123, 'name' => 'John Doe') - * </code> - * - * @param string|mysql_result $result query or mysql result - * @param string $type NUM|ASSOC|BOTH - * returned array should either numeric - * associativ or booth - * @param resource $link mysql link - * - * @return array|boolean first row from result - * or false if result is empty - */ -function PMA_DBI_fetchSingleRow($result, $type = 'ASSOC', $link = null) -{ - if (is_string($result)) { - $result = PMA_DBI_tryQuery($result, $link, PMA_DBI_QUERY_STORE, false); - } - - // return null if result is empty or false - if (! PMA_DBI_numRows($result)) { - return false; - } - - switch ($type) { - case 'NUM' : - $fetch_function = 'PMA_DBI_fetchRow'; - break; - case 'ASSOC' : - $fetch_function = 'PMA_DBI_fetchAssoc'; - break; - case 'BOTH' : - default : - $fetch_function = 'PMA_DBI_fetchArray'; - break; - } - - $row = $fetch_function($result); - PMA_DBI_freeResult($result); - return $row; -} - -/** - * returns all rows in the resultset in one array - * - * <code> - * $sql = 'SELECT * FROM `user`'; - * $users = PMA_DBI_fetchResult($sql); - * // produces - * // $users[] = array('id' => 123, 'name' => 'John Doe') - * - * $sql = 'SELECT `id`, `name` FROM `user`'; - * $users = PMA_DBI_fetchResult($sql, 'id'); - * // produces - * // $users['123'] = array('id' => 123, 'name' => 'John Doe') - * - * $sql = 'SELECT `id`, `name` FROM `user`'; - * $users = PMA_DBI_fetchResult($sql, 0); - * // produces - * // $users['123'] = array(0 => 123, 1 => 'John Doe') - * - * $sql = 'SELECT `id`, `name` FROM `user`'; - * $users = PMA_DBI_fetchResult($sql, 'id', 'name'); - * // or - * $users = PMA_DBI_fetchResult($sql, 0, 1); - * // produces - * // $users['123'] = 'John Doe' - * - * $sql = 'SELECT `name` FROM `user`'; - * $users = PMA_DBI_fetchResult($sql); - * // produces - * // $users[] = 'John Doe' - * - * $sql = 'SELECT `group`, `name` FROM `user`' - * $users = PMA_DBI_fetchResult($sql, array('group', null), 'name'); - * // produces - * // $users['admin'][] = 'John Doe' - * - * $sql = 'SELECT `group`, `name` FROM `user`' - * $users = PMA_DBI_fetchResult($sql, array('group', 'name'), 'id'); - * // produces - * // $users['admin']['John Doe'] = '123' - * </code> - * - * @param string|mysql_result $result query or mysql result - * @param string|integer $key field-name or offset - * used as key for array - * @param string|integer $value value-name or offset - * used as value for array - * @param resource $link mysql link - * @param mixed $options query options - * - * @return array resultrows or values indexed by $key - */ -function PMA_DBI_fetchResult($result, $key = null, $value = null, - $link = null, $options = 0 -) { - $resultrows = array(); - - if (is_string($result)) { - $result = PMA_DBI_tryQuery($result, $link, $options, false); - } - - // return empty array if result is empty or false - if (! $result) { - return $resultrows; - } - - $fetch_function = 'PMA_DBI_fetchAssoc'; - - // no nested array if only one field is in result - if (null === $key && 1 === PMA_DBI_numFields($result)) { - $value = 0; - $fetch_function = 'PMA_DBI_fetchRow'; - } - - // if $key is an integer use non associative mysql fetch function - if (is_int($key)) { - $fetch_function = 'PMA_DBI_fetchRow'; - } - - if (null === $key && null === $value) { - while ($row = $fetch_function($result)) { - $resultrows[] = $row; - } - } elseif (null === $key) { - while ($row = $fetch_function($result)) { - $resultrows[] = $row[$value]; - } - } elseif (null === $value) { - if (is_array($key)) { - while ($row = $fetch_function($result)) { - $result_target =& $resultrows; - foreach ($key as $key_index) { - if (null === $key_index) { - $result_target =& $result_target[]; - continue; - } - - if (! isset($result_target[$row[$key_index]])) { - $result_target[$row[$key_index]] = array(); - } - $result_target =& $result_target[$row[$key_index]]; - } - $result_target = $row; - } - } else { - while ($row = $fetch_function($result)) { - $resultrows[$row[$key]] = $row; - } - } - } else { - if (is_array($key)) { - while ($row = $fetch_function($result)) { - $result_target =& $resultrows; - foreach ($key as $key_index) { - if (null === $key_index) { - $result_target =& $result_target[]; - continue; - } - - if (! isset($result_target[$row[$key_index]])) { - $result_target[$row[$key_index]] = array(); - } - $result_target =& $result_target[$row[$key_index]]; - } - $result_target = $row[$value]; - } - } else { - while ($row = $fetch_function($result)) { - $resultrows[$row[$key]] = $row[$value]; - } - } - } - - PMA_DBI_freeResult($result); - return $resultrows; -} - -/** - * Get supported SQL compatibility modes - * - * @return array supported SQL compatibility modes - */ -function PMA_DBI_getCompatibilities() -{ - // Drizzle doesn't support compatibility modes - if (PMA_DRIZZLE) { - return array(); - } - - $compats = array('NONE'); - $compats[] = 'ANSI'; - $compats[] = 'DB2'; - $compats[] = 'MAXDB'; - $compats[] = 'MYSQL323'; - $compats[] = 'MYSQL40'; - $compats[] = 'MSSQL'; - $compats[] = 'ORACLE'; - // removed; in MySQL 5.0.33, this produces exports that - // can't be read by POSTGRESQL (see our bug #1596328) - //$compats[] = 'POSTGRESQL'; - $compats[] = 'TRADITIONAL'; - - return $compats; -} - -/** - * returns warnings for last query - * - * @param resource $link mysql link resource - * - * @return array warnings - */ -function PMA_DBI_getWarnings($link = null) -{ - if (empty($link)) { - if (isset($GLOBALS['userlink'])) { - $link = $GLOBALS['userlink']; - } else { - return array(); - } - } - - return PMA_DBI_fetchResult('SHOW WARNINGS', null, null, $link); -} - -/** - * returns true (int > 0) if current user is superuser - * otherwise 0 - * - * @return bool Whether use is a superuser - */ -function PMA_isSuperuser() -{ - if (PMA_Util::cacheExists('is_superuser', true)) { - return PMA_Util::cacheGet('is_superuser', true); - } - - // when connection failed we don't have a $userlink - if (isset($GLOBALS['userlink'])) { - if (PMA_DRIZZLE) { - // Drizzle has no authorization by default, so when no plugin is - // enabled everyone is a superuser - // Known authorization libraries: regex_policy, simple_user_policy - // Plugins limit object visibility (dbs, tables, processes), we can - // safely assume we always deal with superuser - $result = true; - } else { - // check access to mysql.user table - $result = (bool) PMA_DBI_tryQuery( - 'SELECT COUNT(*) FROM mysql.user', - $GLOBALS['userlink'], - PMA_DBI_QUERY_STORE - ); - } - PMA_Util::cacheSet('is_superuser', $result, true); - } else { - PMA_Util::cacheSet('is_superuser', false, true); - } - - return PMA_Util::cacheGet('is_superuser', true); -} - -/** - * returns an array of PROCEDURE or FUNCTION names for a db - * - * @param string $db db name - * @param string $which PROCEDURE | FUNCTION - * @param resource $link mysql link - * - * @return array the procedure names or function names - */ -function PMA_DBI_getProceduresOrFunctions($db, $which, $link = null) -{ - if (PMA_DRIZZLE) { - // Drizzle doesn't support functions and procedures - return array(); - } - $shows = PMA_DBI_fetchResult('SHOW ' . $which . ' STATUS;', null, null, $link); - $result = array(); - foreach ($shows as $one_show) { - if ($one_show['Db'] == $db && $one_show['Type'] == $which) { - $result[] = $one_show['Name']; - } - } - return($result); -} - -/** - * returns the definition of a specific PROCEDURE, FUNCTION, EVENT or VIEW - * - * @param string $db db name - * @param string $which PROCEDURE | FUNCTION | EVENT | VIEW - * @param string $name the procedure|function|event|view name - * @param resource $link mysql link - * - * @return string the definition - */ -function PMA_DBI_getDefinition($db, $which, $name, $link = null) -{ - $returned_field = array( - 'PROCEDURE' => 'Create Procedure', - 'FUNCTION' => 'Create Function', - 'EVENT' => 'Create Event', - 'VIEW' => 'Create View' - ); - $query = 'SHOW CREATE ' . $which . ' ' - . PMA_Util::backquote($db) . '.' - . PMA_Util::backquote($name); - return(PMA_DBI_fetchValue($query, 0, $returned_field[$which])); -} - -/** - * returns details about the TRIGGERs for a specific table or database - * - * @param string $db db name - * @param string $table table name - * @param string $delimiter the delimiter to use (may be empty) - * - * @return array information about triggers (may be empty) - */ -function PMA_DBI_getTriggers($db, $table = '', $delimiter = '//') -{ - if (PMA_DRIZZLE) { - // Drizzle doesn't support triggers - return array(); - } - - $result = array(); - if (! $GLOBALS['cfg']['Server']['DisableIS']) { - // Note: in http://dev.mysql.com/doc/refman/5.0/en/faqs-triggers.html - // their example uses WHERE TRIGGER_SCHEMA='dbname' so let's use this - // instead of WHERE EVENT_OBJECT_SCHEMA='dbname' - $query = 'SELECT TRIGGER_SCHEMA, TRIGGER_NAME, EVENT_MANIPULATION' - . ', EVENT_OBJECT_TABLE, ACTION_TIMING, ACTION_STATEMENT' - . ', EVENT_OBJECT_SCHEMA, EVENT_OBJECT_TABLE, DEFINER' - . ' FROM information_schema.TRIGGERS' - . ' WHERE TRIGGER_SCHEMA= \'' . PMA_Util::sqlAddSlashes($db) . '\''; - - if (! empty($table)) { - $query .= " AND EVENT_OBJECT_TABLE = '" - . PMA_Util::sqlAddSlashes($table) . "';"; - } - } else { - $query = "SHOW TRIGGERS FROM " . PMA_Util::backquote($db); - if (! empty($table)) { - $query .= " LIKE '" . PMA_Util::sqlAddSlashes($table, true) . "';"; - } - } - - if ($triggers = PMA_DBI_fetchResult($query)) { - foreach ($triggers as $trigger) { - if ($GLOBALS['cfg']['Server']['DisableIS']) { - $trigger['TRIGGER_NAME'] = $trigger['Trigger']; - $trigger['ACTION_TIMING'] = $trigger['Timing']; - $trigger['EVENT_MANIPULATION'] = $trigger['Event']; - $trigger['EVENT_OBJECT_TABLE'] = $trigger['Table']; - $trigger['ACTION_STATEMENT'] = $trigger['Statement']; - $trigger['DEFINER'] = $trigger['Definer']; - } - $one_result = array(); - $one_result['name'] = $trigger['TRIGGER_NAME']; - $one_result['table'] = $trigger['EVENT_OBJECT_TABLE']; - $one_result['action_timing'] = $trigger['ACTION_TIMING']; - $one_result['event_manipulation'] = $trigger['EVENT_MANIPULATION']; - $one_result['definition'] = $trigger['ACTION_STATEMENT']; - $one_result['definer'] = $trigger['DEFINER']; - - // do not prepend the schema name; this way, importing the - // definition into another schema will work - $one_result['full_trigger_name'] = PMA_Util::backquote( - $trigger['TRIGGER_NAME'] - ); - $one_result['drop'] = 'DROP TRIGGER IF EXISTS ' - . $one_result['full_trigger_name']; - $one_result['create'] = 'CREATE TRIGGER ' - . $one_result['full_trigger_name'] . ' ' - . $trigger['ACTION_TIMING']. ' ' - . $trigger['EVENT_MANIPULATION'] - . ' ON ' . PMA_Util::backquote($trigger['EVENT_OBJECT_TABLE']) - . "\n" . ' FOR EACH ROW ' - . $trigger['ACTION_STATEMENT'] . "\n" . $delimiter . "\n"; - - $result[] = $one_result; - } - } - - // Sort results by name - $name = array(); - foreach ($result as $value) { - $name[] = $value['name']; - } - array_multisort($name, SORT_ASC, $result); - - return($result); -} - -/** - * Formats database error message in a friendly way. - * This is needed because some errors messages cannot - * be obtained by mysql_error(). - * - * @param int $error_number Error code - * @param string $error_message Error message as returned by server - * - * @return string HML text with error details - */ -function PMA_DBI_formatError($error_number, $error_message) -{ - if (! empty($error_message)) { - $error_message = PMA_DBI_convertMessage($error_message); - } - - $error_message = htmlspecialchars($error_message); - - $error = '#' . ((string) $error_number); - - if ($error_number == 2002) { - $error .= ' - ' . $error_message; - $error .= '<br />'; - $error .= __( - 'The server is not responding (or the local server\'s socket' - . ' is not correctly configured).' - ); - } elseif ($error_number == 2003) { - $error .= ' - ' . $error_message; - $error .= '<br />' . __('The server is not responding.'); - } elseif ($error_number == 1005) { - if (strpos($error_message, 'errno: 13') !== false) { - $error .= ' - ' . $error_message; - $error .= '<br />' - . __('Please check privileges of directory containing database.'); - } else { - /* InnoDB contraints, see - * http://dev.mysql.com/doc/refman/5.0/en/ - * innodb-foreign-key-constraints.html - */ - $error .= ' - ' . $error_message . - ' (<a href="server_engines.php' . - PMA_generate_common_url( - array('engine' => 'InnoDB', 'page' => 'Status') - ) . '">' . __('Details…') . '</a>)'; - } - } else { - $error .= ' - ' . $error_message; - } - - return $error; -} - -/** - * Checks whether given schema is a system schema: information_schema - * (MySQL and Drizzle) or data_dictionary (Drizzle) - * - * @param string $schema_name Name of schema (database) to test - * @param bool $test_for_mysql_schema Whether 'mysql' schema should - * be treated the same as IS and DD - * - * @return bool - */ -function PMA_isSystemSchema($schema_name, $test_for_mysql_schema = false) -{ - return strtolower($schema_name) == 'information_schema' - || (!PMA_DRIZZLE && strtolower($schema_name) == 'performance_schema') - || (PMA_DRIZZLE && strtolower($schema_name) == 'data_dictionary') - || ($test_for_mysql_schema && !PMA_DRIZZLE && $schema_name == 'mysql'); -} - -/** - * connects to the database server - * - * @param string $user user name - * @param string $password user password - * @param bool $is_controluser whether this is a control user connection - * @param array $server host/port/socket/persistent - * @param bool $auxiliary_connection (when true, don't go back to login if - * connection fails) - * - * @return mixed false on error or a connection object on success - */ -function PMA_DBI_connect( - $user, $password, $is_controluser = false, $server = null, - $auxiliary_connection = false -) { - return $GLOBALS['extension']->connect( - $user, $password, $is_controluser, $server, $auxiliary_connection - ); -} - -/** - * selects given database - * - * @param string $dbname database name to select - * @param object $link connection object - * - * @return boolean - */ -function PMA_DBI_selectDb($dbname, $link = null) -{ - return $GLOBALS['extension']->selectDb($dbname, $link); -} - -/** - * returns array of rows with associative and numeric keys from $result - * - * @param object $result result set identifier - * - * @return array - */ -function PMA_DBI_fetchArray($result) -{ - return $GLOBALS['extension']->fetchArray($result); -} - -/** - * returns array of rows with associative keys from $result - * - * @param object $result result set identifier - * - * @return array - */ -function PMA_DBI_fetchAssoc($result) -{ - return $GLOBALS['extension']->fetchAssoc($result); -} - -/** - * returns array of rows with numeric keys from $result - * - * @param object $result result set identifier - * - * @return array - */ -function PMA_DBI_fetchRow($result) -{ - return $GLOBALS['extension']->fetchRow($result); -} - -/** - * Adjusts the result pointer to an arbitrary row in the result - * - * @param object $result database result - * @param integer $offset offset to seek - * - * @return bool true on success, false on failure - */ -function PMA_DBI_dataSeek($result, $offset) -{ - return $GLOBALS['extension']->dataSeek($result, $offset); -} - -/** - * Frees memory associated with the result - * - * @param object $result database result - * - * @return void - */ -function PMA_DBI_freeResult($result) -{ - $GLOBALS['extension']->freeResult($result); -} - -/** - * Check if there are any more query results from a multi query - * - * @param object $link the connection object - * - * @return bool true or false - */ -function PMA_DBI_moreResults($link = null) -{ - return $GLOBALS['extension']->moreResults($link = null); -} - -/** - * Prepare next result from multi_query - * - * @param object $link the connection object - * - * @return bool true or false - */ -function PMA_DBI_nextResult($link = null) -{ - return $GLOBALS['extension']->nextResult($link = null); -} - -/** - * Store the result returned from multi query - * - * @return mixed false when empty results / result set when not empty - */ -function PMA_DBI_storeResult() -{ - return $GLOBALS['extension']->storeResult(); -} - -/** - * Returns a string representing the type of connection used - * - * @param object $link mysql link - * - * @return string type of connection used - */ -function PMA_DBI_getHostInfo($link = null) -{ - return $GLOBALS['extension']->getHostInfo($link); -} - -/** - * Returns the version of the MySQL protocol used - * - * @param object $link mysql link - * - * @return integer version of the MySQL protocol used - */ -function PMA_DBI_getProtoInfo($link = null) -{ - return $GLOBALS['extension']->getProtoInfo($link); -} - -/** - * returns a string that represents the client library version - * - * @return string MySQL client library version - */ -function PMA_DBI_getClientInfo() -{ - return $GLOBALS['extension']->getClientInfo(); -} - -/** - * returns last error message or false if no errors occured - * - * @param object $link connection link - * - * @return string|bool $error or false - */ -function PMA_DBI_getError($link = null) -{ - return $GLOBALS['extension']->getError($link); -} - -/** - * returns the number of rows returned by last query - * - * @param object $result result set identifier - * - * @return string|int - */ -function PMA_DBI_numRows($result) -{ - return $GLOBALS['extension']->numRows($result); -} - -/** - * returns last inserted auto_increment id for given $link or $GLOBALS['userlink'] - * - * @param object $link the connection object - * - * @return string|int - */ -function PMA_DBI_insertId($link = null) -{ - return $GLOBALS['extension']->insertId($link); -} - -/** - * returns the number of rows affected by last query - * - * @param object $link the connection object - * @param bool $get_from_cache whether to retrieve from cache - * - * @return string|int - */ -function PMA_DBI_affectedRows($link = null, $get_from_cache = true) -{ - return $GLOBALS['extension']->affectedRows($link, $get_from_cache); -} - -/** - * returns metainfo for fields in $result - * - * @param object $result result set identifier - * - * @return array meta info for fields in $result - */ -function PMA_DBI_getFieldsMeta($result) -{ - return $GLOBALS['extension']->getFieldsMeta($result); -} - -/** - * return number of fields in given $result - * - * @param object $result result set identifier - * - * @return int field count - */ -function PMA_DBI_numFields($result) -{ - return $GLOBALS['extension']->numFields($result); -} - -/** - * returns the length of the given field $i in $result - * - * @param object $result result set identifier - * @param int $i field - * - * @return int length of field - */ -function PMA_DBI_fieldLen($result, $i) -{ - return $GLOBALS['extension']->fieldLen($result, $i); -} - -/** - * returns name of $i. field in $result - * - * @param object $result result set identifier - * @param int $i field - * - * @return string name of $i. field in $result - */ -function PMA_DBI_fieldName($result, $i) -{ - return $GLOBALS['extension']->fieldName($result, $i); -} - -/** - * returns concatenated string of human readable field flags - * - * @param object $result result set identifier - * @param int $i field - * - * @return string field flags - */ -function PMA_DBI_fieldFlags($result, $i) -{ - return $GLOBALS['extension']->fieldFlags($result, $i); -} -?> diff --git a/libraries/db_common.inc.php b/libraries/db_common.inc.php index c9c260a598..3c23895224 100644 --- a/libraries/db_common.inc.php +++ b/libraries/db_common.inc.php @@ -18,7 +18,7 @@ PMA_Util::checkParameters(array('db')); $is_show_stats = $cfg['ShowStats']; -$db_is_information_schema = PMA_isSystemSchema($db); +$db_is_information_schema = $GLOBALS['dbi']->isSystemSchema($db); if ($db_is_information_schema) { $is_show_stats = false; } @@ -36,11 +36,11 @@ $err_url = $cfg['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db); */ if (! isset($is_db) || ! $is_db) { if (strlen($db)) { - $is_db = PMA_DBI_selectDb($db); + $is_db = $GLOBALS['dbi']->selectDb($db); // This "Command out of sync" 2014 error may happen, for example // after calling a MySQL procedure; at this point we can't select // the db but it's not necessarily wrong - if (PMA_DBI_getError() && $GLOBALS['errno'] == 2014) { + if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) { $is_db = true; unset($GLOBALS['errno']); } @@ -75,7 +75,7 @@ if (isset($_REQUEST['submitcollation']) $sql_query = 'ALTER DATABASE ' . PMA_Util::backquote($db) . ' DEFAULT' . PMA_generateCharsetQueryPart($_REQUEST['db_collation']); - $result = PMA_DBI_query($sql_query); + $result = $GLOBALS['dbi']->query($sql_query); $message = PMA_Message::success(); unset($db_charset); diff --git a/libraries/db_info.inc.php b/libraries/db_info.inc.php index 0af60a507d..80ed54beb6 100644 --- a/libraries/db_info.inc.php +++ b/libraries/db_info.inc.php @@ -41,7 +41,7 @@ $is_show_stats = $cfg['ShowStats']; */ $db_is_information_schema = false; -if (PMA_isSystemSchema($db)) { +if ($GLOBALS['dbi']->isSystemSchema($db)) { $is_show_stats = false; $db_is_information_schema = true; } @@ -66,34 +66,34 @@ $tooltip_aliasname = array(); // Special speedup for newer MySQL Versions (in 4.0 format changed) if (true === $cfg['SkipLockedTables']) { - $db_info_result = PMA_DBI_query( + $db_info_result = $GLOBALS['dbi']->query( 'SHOW OPEN TABLES FROM ' . PMA_Util::backquote($db) . ';' ); // Blending out tables in use - if ($db_info_result && PMA_DBI_numRows($db_info_result) > 0) { - while ($tmp = PMA_DBI_fetchRow($db_info_result)) { + if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) { + while ($tmp = $GLOBALS['dbi']->fetchRow($db_info_result)) { // if in use memorize tablename if (preg_match('@in_use=[1-9]+@i', $tmp[1])) { $sot_cache[$tmp[0]] = true; } } - PMA_DBI_freeResult($db_info_result); + $GLOBALS['dbi']->freeResult($db_info_result); if (isset($sot_cache)) { - $db_info_result = PMA_DBI_query( + $db_info_result = $GLOBALS['dbi']->query( 'SHOW TABLES FROM ' . PMA_Util::backquote($db) . $tbl_group_sql . ';', null, PMA_DBI_QUERY_STORE ); - if ($db_info_result && PMA_DBI_numRows($db_info_result) > 0) { - while ($tmp = PMA_DBI_fetchRow($db_info_result)) { + if ($db_info_result && $GLOBALS['dbi']->numRows($db_info_result) > 0) { + while ($tmp = $GLOBALS['dbi']->fetchRow($db_info_result)) { if (! isset($sot_cache[$tmp[0]])) { - $sts_result = PMA_DBI_query( + $sts_result = $GLOBALS['dbi']->query( 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' LIKE \'' . PMA_Util::sqlAddSlashes($tmp[0], true) . '\';' ); - $sts_tmp = PMA_DBI_fetchAssoc($sts_result); - PMA_DBI_freeResult($sts_result); + $sts_tmp = $GLOBALS['dbi']->fetchAssoc($sts_result); + $GLOBALS['dbi']->freeResult($sts_result); unset($sts_result); if (! isset($sts_tmp['Type']) && isset($sts_tmp['Engine'])) { @@ -123,13 +123,13 @@ if (true === $cfg['SkipLockedTables']) { $sot_ready = true; } elseif ($db_info_result) { - PMA_DBI_freeResult($db_info_result); + $GLOBALS['dbi']->freeResult($db_info_result); } unset($sot_cache); } unset($tmp); } elseif ($db_info_result) { - PMA_DBI_freeResult($db_info_result); + $GLOBALS['dbi']->freeResult($db_info_result); } } @@ -163,14 +163,14 @@ if (! isset($sot_ready)) { if (! empty($tbl_group)) { // only tables for selected group - $tables = PMA_DBI_getTablesFull( + $tables = $GLOBALS['dbi']->getTablesFull( $db, $tbl_group, true, null, 0, false, $sort, $sort_order ); } else { // all tables in db // - get the total number of tables // (needed for proper working of the MaxTableList feature) - $tables = PMA_DBI_getTables($db); + $tables = $GLOBALS['dbi']->getTables($db); $total_num_tables = count($tables); if (isset($sub_part) && $sub_part == '_export') { // (don't fetch only a subset if we are coming from db_export.php, @@ -180,12 +180,12 @@ if (! isset($sot_ready)) { * * @todo Page selector for table names? */ - $tables = PMA_DBI_getTablesFull( + $tables = $GLOBALS['dbi']->getTablesFull( $db, false, false, null, 0, false, $sort, $sort_order ); } else { // fetch the details for a possible limited subset - $tables = PMA_DBI_getTablesFull( + $tables = $GLOBALS['dbi']->getTablesFull( $db, false, false, null, $pos, true, $sort, $sort_order ); } diff --git a/libraries/db_table_exists.lib.php b/libraries/db_table_exists.lib.php index 143f6f86d9..2722e4f1ac 100644 --- a/libraries/db_table_exists.lib.php +++ b/libraries/db_table_exists.lib.php @@ -12,7 +12,7 @@ if (! defined('PHPMYADMIN')) { if (empty($is_db)) { if (strlen($db)) { - $is_db = @PMA_DBI_selectDb($db); + $is_db = @$GLOBALS['dbi']->selectDb($db); } else { $is_db = false; } @@ -58,13 +58,13 @@ if (empty($is_table) $is_table = isset(PMA_Table::$cache[$db][$table]); if (! $is_table) { - $_result = PMA_DBI_tryQuery( + $_result = $GLOBALS['dbi']->tryQuery( 'SHOW TABLES LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\';', null, PMA_DBI_QUERY_STORE ); - $is_table = @PMA_DBI_numRows($_result); - PMA_DBI_freeResult($_result); + $is_table = @$GLOBALS['dbi']->numRows($_result); + $GLOBALS['dbi']->freeResult($_result); } } else { $is_table = false; @@ -81,13 +81,13 @@ if (empty($is_table) * @todo should this check really * only happen if IS_TRANSFORMATION_WRAPPER? */ - $_result = PMA_DBI_tryQuery( + $_result = $GLOBALS['dbi']->tryQuery( 'SELECT COUNT(*) FROM ' . PMA_Util::backquote($table) . ';', null, PMA_DBI_QUERY_STORE ); - $is_table = ($_result && @PMA_DBI_numRows($_result)); - PMA_DBI_freeResult($_result); + $is_table = ($_result && @$GLOBALS['dbi']->numRows($_result)); + $GLOBALS['dbi']->freeResult($_result); } if (! $is_table) { diff --git a/libraries/dbi/DBIDrizzle.class.php b/libraries/dbi/DBIDrizzle.class.php index 940f130f09..f3f1dc8a8a 100644 --- a/libraries/dbi/DBIDrizzle.class.php +++ b/libraries/dbi/DBIDrizzle.class.php @@ -150,7 +150,7 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension ); return false; } - // we could be calling PMA_DBI_connect() to connect to another + // we could be calling $GLOBALS['dbi']->connect() to connect to another // server, for example in the Synchronize feature, so do not // go back to main login if it fails if (! $auxiliary_connection) { @@ -161,7 +161,7 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension return false; } } else { - PMA_DBI_postConnect($link, $is_controluser); + $GLOBALS['dbi']->postConnect($link, $is_controluser); } return $link; @@ -388,7 +388,7 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension // the call to getError() $GLOBALS['errno'] = $error_number; - return PMA_DBI_formatError($error_number, $error_message); + return $GLOBALS['dbi']->formatError($error_number, $error_message); } /** @@ -400,7 +400,7 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension */ public function numRows($result) { - // see the note for PMA_DBI_tryQuery(); + // see the note for $GLOBALS['dbi']->tryQuery(); if (!is_bool($result)) { return @$result->numRows(); } else { @@ -431,7 +431,7 @@ class PMA_DBI_Drizzle implements PMA_DBI_Extension // When no controluser is defined, using mysqli_insert_id($link) // does not always return the last insert id due to a mixup with // the tracking mechanism, but this works: - return PMA_DBI_fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link); + return $GLOBALS['dbi']->fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link); // Curiously, this problem does not happen with the mysql extension but // there is another problem with BIGINT primary keys so insertId() // in the mysql extension also uses this logic. diff --git a/libraries/dbi/DBIMysql.class.php b/libraries/dbi/DBIMysql.class.php index dc00400a48..f90e2f70a0 100644 --- a/libraries/dbi/DBIMysql.class.php +++ b/libraries/dbi/DBIMysql.class.php @@ -174,7 +174,7 @@ class PMA_DBI_Mysql implements PMA_DBI_Extension ); return false; } - // we could be calling PMA_DBI_connect() to connect to another + // we could be calling $GLOBALS['dbi']->connect() to connect to another // server, for example in the Synchronize feature, so do not // go back to main login if it fails if (! $auxiliary_connection) { @@ -186,7 +186,7 @@ class PMA_DBI_Mysql implements PMA_DBI_Extension } } // end if if (! $server) { - PMA_DBI_postConnect($link, $is_controluser); + $GLOBALS['dbi']->postConnect($link, $is_controluser); } return $link; } @@ -410,7 +410,7 @@ class PMA_DBI_Mysql implements PMA_DBI_Extension // the call to getError() $GLOBALS['errno'] = $error_number; - return PMA_DBI_formatError($error_number, $error_message); + return $GLOBALS['dbi']->formatError($error_number, $error_message); } /** @@ -451,7 +451,7 @@ class PMA_DBI_Mysql implements PMA_DBI_Extension // and in the present function we don't know if the PK is BIGINT // so better play safe and use LAST_INSERT_ID() // - return PMA_DBI_fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link); + return $GLOBALS['dbi']->fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link); } /** diff --git a/libraries/dbi/DBIMysqli.class.php b/libraries/dbi/DBIMysqli.class.php index 17c922a0db..c85c5b9174 100644 --- a/libraries/dbi/DBIMysqli.class.php +++ b/libraries/dbi/DBIMysqli.class.php @@ -219,7 +219,7 @@ class PMA_DBI_Mysqli implements PMA_DBI_Extension ); return false; } - // we could be calling PMA_DBI_connect() to connect to another + // we could be calling $GLOBALS['dbi']->connect() to connect to another // server, for example in the Synchronize feature, so do not // go back to main login if it fails if (! $auxiliary_connection) { @@ -230,7 +230,7 @@ class PMA_DBI_Mysqli implements PMA_DBI_Extension return false; } } else { - PMA_DBI_postConnect($link, $is_controluser); + $GLOBALS['dbi']->postConnect($link, $is_controluser); } return $link; @@ -492,7 +492,7 @@ class PMA_DBI_Mysqli implements PMA_DBI_Extension // the call to getError() $GLOBALS['errno'] = $error_number; - return PMA_DBI_formatError($error_number, $error_message); + return $GLOBALS['dbi']->formatError($error_number, $error_message); } /** @@ -532,7 +532,7 @@ class PMA_DBI_Mysqli implements PMA_DBI_Extension // When no controluser is defined, using mysqli_insert_id($link) // does not always return the last insert id due to a mixup with // the tracking mechanism, but this works: - return PMA_DBI_fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link); + return $GLOBALS['dbi']->fetchValue('SELECT LAST_INSERT_ID();', 0, 0, $link); // Curiously, this problem does not happen with the mysql extension but // there is another problem with BIGINT primary keys so insertId() // in the mysql extension also uses this logic. diff --git a/libraries/engines/innodb.lib.php b/libraries/engines/innodb.lib.php index 5c3c1e9eba..c7b639b25a 100644 --- a/libraries/engines/innodb.lib.php +++ b/libraries/engines/innodb.lib.php @@ -159,7 +159,7 @@ class PMA_StorageEngine_innodb extends PMA_StorageEngine SHOW STATUS WHERE Variable_name LIKE \'Innodb\\_buffer\\_pool\\_%\' OR Variable_name = \'Innodb_page_size\';'; - $status = PMA_DBI_fetchResult($sql, 0, 1); + $status = $GLOBALS['dbi']->fetchResult($sql, 0, 1); $output = '<table class="data" id="table_innodb_bufferpool_usage">' . "\n" . ' <caption class="tblHeaders">' . "\n" @@ -322,7 +322,7 @@ class PMA_StorageEngine_innodb extends PMA_StorageEngine { return '<pre id="pre_innodb_status">' . "\n" . htmlspecialchars( - PMA_DBI_fetchValue('SHOW INNODB STATUS;', 0, 'Status') + $GLOBALS['dbi']->fetchValue('SHOW INNODB STATUS;', 0, 'Status') ) . "\n" . '</pre>' . "\n"; } @@ -366,7 +366,7 @@ class PMA_StorageEngine_innodb extends PMA_StorageEngine */ function getInnodbPluginVersion() { - return PMA_DBI_fetchValue('SELECT @@innodb_version;'); + return $GLOBALS['dbi']->fetchValue('SELECT @@innodb_version;'); } /** @@ -380,7 +380,7 @@ class PMA_StorageEngine_innodb extends PMA_StorageEngine */ function getInnodbFileFormat() { - return PMA_DBI_fetchValue( + return $GLOBALS['dbi']->fetchValue( "SHOW GLOBAL VARIABLES LIKE 'innodb_file_format';", 0, 1 ); } @@ -396,7 +396,7 @@ class PMA_StorageEngine_innodb extends PMA_StorageEngine */ function supportsFilePerTable() { - $innodb_file_per_table = PMA_DBI_fetchValue( + $innodb_file_per_table = $GLOBALS['dbi']->fetchValue( "SHOW GLOBAL VARIABLES LIKE 'innodb_file_per_table';", 0, 1 ); if ($innodb_file_per_table == 'ON') { diff --git a/libraries/import.lib.php b/libraries/import.lib.php index 549d27b195..c02bb8b969 100644 --- a/libraries/import.lib.php +++ b/libraries/import.lib.php @@ -155,7 +155,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, $import_run_buffer['sql'] ); } else { - $result = PMA_DBI_tryQuery($import_run_buffer['sql']); + $result = $GLOBALS['dbi']->tryQuery($import_run_buffer['sql']); } $msg = '# '; @@ -165,7 +165,7 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, } $my_die[] = array( 'sql' => $import_run_buffer['full'], - 'error' => PMA_DBI_getError() + 'error' => $GLOBALS['dbi']->getError() ); $msg .= __('Error'); @@ -175,8 +175,8 @@ function PMA_importRunQuery($sql = '', $full = '', $controluser = false, return; } } else { - $a_num_rows = (int)@PMA_DBI_numRows($result); - $a_aff_rows = (int)@PMA_DBI_affectedRows(); + $a_num_rows = (int)@$GLOBALS['dbi']->numRows($result); + $a_aff_rows = (int)@$GLOBALS['dbi']->affectedRows(); if ($a_num_rows > 0) { $msg .= __('Rows'). ': ' . $a_num_rows; $last_query_with_results = $import_run_buffer['sql']; diff --git a/libraries/insert_edit.lib.php b/libraries/insert_edit.lib.php index 1740b5a0b0..e2942c03bd 100644 --- a/libraries/insert_edit.lib.php +++ b/libraries/insert_edit.lib.php @@ -82,8 +82,8 @@ function PMA_analyzeWhereClauses( . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . ' WHERE ' . $where_clause . ';'; - $result[$key_id] = PMA_DBI_query($local_query, null, PMA_DBI_QUERY_STORE); - $rows[$key_id] = PMA_DBI_fetchAssoc($result[$key_id]); + $result[$key_id] = $GLOBALS['dbi']->query($local_query, null, PMA_DBI_QUERY_STORE); + $rows[$key_id] = $GLOBALS['dbi']->fetchAssoc($result[$key_id]); $where_clauses[$key_id] = str_replace('\\', '\\\\', $where_clause); $has_unique_condition = PMA_showEmptyResultMessageOrSetUniqueCondition( @@ -126,7 +126,7 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, * exit if we want the message to be displayed */ } else {// end if (no row returned) - $meta = PMA_DBI_getFieldsMeta($result[$key_id]); + $meta = $GLOBALS['dbi']->getFieldsMeta($result[$key_id]); list($unique_condition, $tmp_clause_is_unique) = PMA_Util::getUniqueCondition( @@ -151,7 +151,7 @@ function PMA_showEmptyResultMessageOrSetUniqueCondition($rows, $key_id, */ function PMA_loadFirstRow($table, $db) { - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SELECT * FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) . ' LIMIT 1;', null, @@ -1786,9 +1786,9 @@ function PMA_setSessionForEditNext($one_where_clause) . '.' . PMA_Util::backquote($GLOBALS['table']) . ' WHERE ' . str_replace('` =', '` >', $one_where_clause) . ' LIMIT 1;'; - $res = PMA_DBI_query($local_query); - $row = PMA_DBI_fetchRow($res); - $meta = PMA_DBI_getFieldsMeta($res); + $res = $GLOBALS['dbi']->query($local_query); + $row = $GLOBALS['dbi']->fetchRow($res); + $meta = $GLOBALS['dbi']->getFieldsMeta($res); // must find a unique condition based on unique key, // not a combination of all fields list($unique_condition, $clause_is_unique) @@ -1913,20 +1913,20 @@ function PMA_executeSqlQuery($url_params, $query) continue; } if ($GLOBALS['cfg']['IgnoreMultiSubmitErrors']) { - $result = PMA_DBI_tryQuery($single_query); + $result = $GLOBALS['dbi']->tryQuery($single_query); } else { - $result = PMA_DBI_query($single_query); + $result = $GLOBALS['dbi']->query($single_query); } if (! $result) { - $error_messages[] = PMA_Message::sanitize(PMA_DBI_getError()); + $error_messages[] = PMA_Message::sanitize($GLOBALS['dbi']->getError()); } else { // The next line contains a real assignment, it's not a typo - if ($tmp = @PMA_DBI_affectedRows()) { + if ($tmp = @$GLOBALS['dbi']->affectedRows()) { $total_affected_rows += $tmp; } unset($tmp); - $insert_id = PMA_DBI_insertId(); + $insert_id = $GLOBALS['dbi']->insertId(); if ($insert_id != 0) { // insert_id is id of FIRST record inserted in one insert, so if we // inserted multiple rows, we had to increment this @@ -1938,7 +1938,7 @@ function PMA_executeSqlQuery($url_params, $query) $last_message->addParam($insert_id); $last_messages[] = $last_message; } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } $warning_messages = PMA_getWarningMessages(); } @@ -1960,7 +1960,7 @@ function PMA_executeSqlQuery($url_params, $query) function PMA_getWarningMessages() { $warning_essages = array(); - foreach (PMA_DBI_getWarnings() as $warning) { + foreach ($GLOBALS['dbi']->getWarnings() as $warning) { $warning_essages[] = PMA_Message::sanitize( $warning['Level'] . ': #' . $warning['Code'] . ' ' . $warning['Message'] ); @@ -1993,11 +1993,11 @@ function PMA_getDisplayValueForForeignTableColumn($where_comparison, . '.' . PMA_Util::backquote($map[$relation_field]['foreign_table']) . ' WHERE ' . PMA_Util::backquote($map[$relation_field]['foreign_field']) . $where_comparison; - $dispresult = PMA_DBI_tryQuery($dispsql, null, PMA_DBI_QUERY_STORE); - if ($dispresult && PMA_DBI_numRows($dispresult) > 0) { - list($dispval) = PMA_DBI_fetchRow($dispresult, 0); + $dispresult = $GLOBALS['dbi']->tryQuery($dispsql, null, PMA_DBI_QUERY_STORE); + if ($dispresult && $GLOBALS['dbi']->numRows($dispresult) > 0) { + list($dispval) = $GLOBALS['dbi']->fetchRow($dispresult, 0); } - @PMA_DBI_freeResult($dispresult); + @$GLOBALS['dbi']->freeResult($dispresult); return $dispval; } return ''; @@ -2133,7 +2133,7 @@ function PMA_getCurrentValueAsAnArrayForMultipleEdit($multi_edit_colummns, return $current_value; } elseif ('UUID' === $multi_edit_funcs[$key]) { /* This way user will know what UUID new row has */ - $uuid = PMA_DBI_fetchValue('SELECT UUID()'); + $uuid = $GLOBALS['dbi']->fetchValue('SELECT UUID()'); return "'" . $uuid . "'"; } elseif ((in_array($multi_edit_funcs[$key], $gis_from_text_functions) && substr($current_value, 0, 3) == "'''") @@ -2257,7 +2257,7 @@ function PMA_getCurrentValueForDifferentTypes($possibly_uploaded_val, $key, && $using_key && isset($multi_edit_columns_type) && is_array($multi_edit_columns_type) && isset($where_clause) ) { - $protected_row = PMA_DBI_fetchSingleRow( + $protected_row = $GLOBALS['dbi']->fetchSingleRow( 'SELECT * FROM ' . PMA_Util::backquote($table) . ' WHERE ' . $where_clause . ';' ); @@ -2360,8 +2360,8 @@ function PMA_verifyWhetherValueCanBeTruncatedAndAppendExtraData( . PMA_Util::backquote($table) . ' WHERE ' . $_REQUEST['where_clause'][0]; - if (PMA_DBI_fetchValue($sql_for_real_value) !== false) { - $extra_data['truncatableFieldValue'] = PMA_DBI_fetchValue($sql_for_real_value); + if ($GLOBALS['dbi']->fetchValue($sql_for_real_value) !== false) { + $extra_data['truncatableFieldValue'] = $GLOBALS['dbi']->fetchValue($sql_for_real_value); } else { $extra_data['isNeedToRecheck'] = false; } diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 2dca9cfc67..7f403d89db 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -90,18 +90,18 @@ if (! empty($submit_mult) break; case 'primary': // Gets table primary key - PMA_DBI_selectDb($db); - $result = PMA_DBI_query( + $GLOBALS['dbi']->selectDb($db); + $result = $GLOBALS['dbi']->query( 'SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';' ); $primary = ''; - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; } } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); if (empty($primary)) { // no primary key, so we can safely create new unset($submit_mult); @@ -147,7 +147,7 @@ if (! empty($submit_mult) } } // end if -$views = PMA_DBI_getVirtualTables($db); +$views = $GLOBALS['dbi']->getVirtualTables($db); /** * Displays the confirmation form if required @@ -351,7 +351,7 @@ if (!empty($submit_mult) && !empty($what)) { echo '</span>'; echo '<span class="checkbox">'; echo '<input type="checkbox" name="fk_check" value="1" id="fkc_checkbox"'; - $default_fk_check_value = PMA_DBI_fetchValue('SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1) == 'ON'; + $default_fk_check_value = $GLOBALS['dbi']->fetchValue('SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1) == 'ON'; if ($default_fk_check_value) { echo ' checked="checked"'; } @@ -397,18 +397,18 @@ if (!empty($submit_mult) && !empty($what)) { if ($query_type == 'primary_fld') { // Gets table primary key - PMA_DBI_selectDb($db); - $result = PMA_DBI_query( + $GLOBALS['dbi']->selectDb($db); + $result = $GLOBALS['dbi']->query( 'SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';' ); $primary = ''; - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; } } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } $rebuild_database_list = false; @@ -557,9 +557,9 @@ if (!empty($submit_mult) && !empty($what)) { if ($run_parts) { $sql_query .= $a_query . ';' . "\n"; if ($query_type != 'drop_db') { - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); } - $result = PMA_DBI_query($a_query); + $result = $GLOBALS['dbi']->query($a_query); if ($query_type == 'drop_db') { PMA_clearTransformations($selected[$i]); @@ -573,7 +573,7 @@ if (!empty($submit_mult) && !empty($what)) { } // end for if ($query_type == 'drop_tbl') { - $default_fk_check_value = PMA_DBI_fetchValue('SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1) == 'ON'; + $default_fk_check_value = $GLOBALS['dbi']->fetchValue('SHOW VARIABLES LIKE \'foreign_key_checks\';', 0, 1) == 'ON'; if (!empty($sql_query)) { $sql_query .= ';'; } elseif (!empty($sql_query_views)) { @@ -585,26 +585,26 @@ if (!empty($submit_mult) && !empty($what)) { if ($use_sql) { include './sql.php'; } elseif (!$run_parts) { - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); // for disabling foreign key checks while dropping tables if (! isset($_REQUEST['fk_check']) && $query_type == 'drop_tbl') { - PMA_DBI_query('SET FOREIGN_KEY_CHECKS = 0;'); + $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 0;'); } - $result = PMA_DBI_tryQuery($sql_query); + $result = $GLOBALS['dbi']->tryQuery($sql_query); if (! isset($_REQUEST['fk_check']) && $query_type == 'drop_tbl' && $default_fk_check_value ) { - PMA_DBI_query('SET FOREIGN_KEY_CHECKS = 1;'); + $GLOBALS['dbi']->query('SET FOREIGN_KEY_CHECKS = 1;'); } if ($result && !empty($sql_query_views)) { $sql_query .= ' ' . $sql_query_views . ';'; - $result = PMA_DBI_tryQuery($sql_query_views); + $result = $GLOBALS['dbi']->tryQuery($sql_query_views); unset($sql_query_views); } if (! $result) { - $message = PMA_Message::error(PMA_DBI_getError()); + $message = PMA_Message::error($GLOBALS['dbi']->getError()); } } if ($rebuild_database_list) { diff --git a/libraries/mysql_charsets.lib.php b/libraries/mysql_charsets.lib.php index 649fca9928..d2b1998ff3 100644 --- a/libraries/mysql_charsets.lib.php +++ b/libraries/mysql_charsets.lib.php @@ -19,17 +19,17 @@ if (! PMA_Util::cacheExists('mysql_charsets', true)) { $sql = PMA_DRIZZLE ? 'SELECT * FROM data_dictionary.CHARACTER_SETS' : 'SELECT * FROM information_schema.CHARACTER_SETS'; - $res = PMA_DBI_query($sql); + $res = $GLOBALS['dbi']->query($sql); $mysql_charsets = array(); - while ($row = PMA_DBI_fetchAssoc($res)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { $mysql_charsets[] = $row['CHARACTER_SET_NAME']; // never used //$mysql_charsets_maxlen[$row['Charset']] = $row['Maxlen']; $mysql_charsets_descriptions[$row['CHARACTER_SET_NAME']] = $row['DESCRIPTION']; } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); sort($mysql_charsets, SORT_STRING); @@ -40,8 +40,8 @@ if (! PMA_Util::cacheExists('mysql_charsets', true)) { $sql = PMA_DRIZZLE ? 'SELECT * FROM data_dictionary.COLLATIONS' : 'SELECT * FROM information_schema.COLLATIONS'; - $res = PMA_DBI_query($sql); - while ($row = PMA_DBI_fetchAssoc($res)) { + $res = $GLOBALS['dbi']->query($sql); + while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { if (! is_array($mysql_collations[$row['CHARACTER_SET_NAME']])) { $mysql_collations[$row['CHARACTER_SET_NAME']] = array($row['COLLATION_NAME']); @@ -60,7 +60,7 @@ if (! PMA_Util::cacheExists('mysql_charsets', true)) { = !empty($mysql_charsets_available[$row['CHARACTER_SET_NAME']]) || !empty($mysql_collations_available[$row['COLLATION_NAME']]); } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); unset($res, $row); if (PMA_DRIZZLE @@ -186,7 +186,7 @@ function PMA_generateCharsetQueryPart($collation) */ function PMA_getDbCollation($db) { - if (PMA_isSystemSchema($db)) { + if ($GLOBALS['dbi']->isSystemSchema($db)) { // We don't have to check the collation of the virtual // information_schema database: We know it! return 'utf8_general_ci'; @@ -201,14 +201,14 @@ function PMA_getDbCollation($db) : 'SELECT DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA' . ' WHERE SCHEMA_NAME = \'' . PMA_Util::sqlAddSlashes($db) . '\' LIMIT 1'; - return PMA_DBI_fetchValue($sql); + return $GLOBALS['dbi']->fetchValue($sql); } else { - PMA_DBI_selectDb($db); - $return = PMA_DBI_fetchValue( + $GLOBALS['dbi']->selectDb($db); + $return = $GLOBALS['dbi']->fetchValue( 'SHOW VARIABLES LIKE \'collation_database\'', 0, 1 ); if ($db !== $GLOBALS['db']) { - PMA_DBI_selectDb($GLOBALS['db']); + $GLOBALS['dbi']->selectDb($GLOBALS['db']); } return $return; } @@ -221,7 +221,7 @@ function PMA_getDbCollation($db) */ function PMA_getServerCollation() { - return PMA_DBI_fetchValue( + return $GLOBALS['dbi']->fetchValue( 'SHOW VARIABLES LIKE \'collation_server\'', 0, 1 ); } diff --git a/libraries/navigation/NavigationTree.class.php b/libraries/navigation/NavigationTree.class.php index 29924ab173..49973e779b 100644 --- a/libraries/navigation/NavigationTree.class.php +++ b/libraries/navigation/NavigationTree.class.php @@ -160,7 +160,7 @@ class PMA_NavigationTree $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; $query .= "WHERE `SCHEMA_NAME` < '%s' "; $query .= "ORDER BY `SCHEMA_NAME` ASC"; - $retval = PMA_DBI_fetchValue( + $retval = $GLOBALS['dbi']->fetchValue( sprintf( $query, (int)$GLOBALS['cfg']['MaxNavigationItems'], diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index a3253ef2e2..07c1d00842 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -365,7 +365,7 @@ class Node $query .= $this->_getWhereClause($searchClause); $query .= "ORDER BY `SCHEMA_NAME` ASC "; $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; - return PMA_DBI_fetchResult($query); + return $GLOBALS['dbi']->fetchResult($query); } /** @@ -395,7 +395,7 @@ class Node $query = "SELECT COUNT(*) "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; $query .= $this->_getWhereClause($searchClause); - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $query = "SHOW DATABASES "; if (! empty($searchClause)) { @@ -405,7 +405,7 @@ class Node ); $query .= "%' "; } - $retval = PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = $GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } return $retval; } diff --git a/libraries/navigation/Nodes/Node_Column.class.php b/libraries/navigation/Nodes/Node_Column.class.php index b66554718f..efe98d024a 100644 --- a/libraries/navigation/Nodes/Node_Column.class.php +++ b/libraries/navigation/Nodes/Node_Column.class.php @@ -64,7 +64,7 @@ class Node_Column extends Node $query .= "WHERE `TABLE_SCHEMA`='$db' "; $query .= "AND `TABLE_NAME`='$table' "; $query .= "AND `COLUMN_NAME`='$column' "; - return PMA_DBI_fetchValue($query); + return $GLOBALS['dbi']->fetchValue($query); } } diff --git a/libraries/navigation/Nodes/Node_Database.class.php b/libraries/navigation/Nodes/Node_Database.class.php index 66212b8024..f0d1b1b272 100644 --- a/libraries/navigation/Nodes/Node_Database.class.php +++ b/libraries/navigation/Nodes/Node_Database.class.php @@ -67,7 +67,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $query = "SHOW FULL TABLES FROM "; $query .= PMA_Util::backquote($db); @@ -81,7 +81,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = $GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; case 'views': @@ -98,7 +98,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $query = "SHOW FULL TABLES FROM "; $query .= PMA_Util::backquote($db); @@ -112,7 +112,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = $GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; case 'procedures': @@ -129,7 +129,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $db = PMA_Util::sqlAddSlashes($db); $query = "SHOW PROCEDURE STATUS WHERE `Db`='$db' "; @@ -140,7 +140,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = $GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; case 'functions': @@ -157,7 +157,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $db = PMA_Util::sqlAddSlashes($db); $query = "SHOW FUNCTION STATUS WHERE `Db`='$db' "; @@ -168,7 +168,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = $GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; case 'events': @@ -184,7 +184,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $db = PMA_Util::backquote($db); $query = "SHOW EVENTS FROM $db "; @@ -195,7 +195,7 @@ class Node_Database extends Node ); $query .= "%'"; } - $retval = PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = $GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; default: @@ -237,7 +237,7 @@ class Node_Database extends Node } $query .= "ORDER BY `TABLE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $query = " SHOW FULL TABLES FROM "; $query .= PMA_Util::backquote($db); @@ -251,10 +251,10 @@ class Node_Database extends Node ); $query .= "%'"; } - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr[0]; $count++; @@ -280,7 +280,7 @@ class Node_Database extends Node } $query .= "ORDER BY `TABLE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $query = "SHOW FULL TABLES FROM "; $query .= PMA_Util::backquote($db); @@ -294,10 +294,10 @@ class Node_Database extends Node ); $query .= "%'"; } - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr[0]; $count++; @@ -323,7 +323,7 @@ class Node_Database extends Node } $query .= "ORDER BY `ROUTINE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $db = PMA_Util::sqlAddSlashes($db); $query = "SHOW PROCEDURE STATUS WHERE `Db`='$db' "; @@ -334,10 +334,10 @@ class Node_Database extends Node ); $query .= "%'"; } - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Name']; $count++; @@ -363,7 +363,7 @@ class Node_Database extends Node } $query .= "ORDER BY `ROUTINE_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $db = PMA_Util::sqlAddSlashes($db); $query = "SHOW FUNCTION STATUS WHERE `Db`='$db' "; @@ -374,10 +374,10 @@ class Node_Database extends Node ); $query .= "%'"; } - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Name']; $count++; @@ -402,7 +402,7 @@ class Node_Database extends Node } $query .= "ORDER BY `EVENT_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $db = PMA_Util::backquote($db); $query = "SHOW EVENTS FROM $db "; @@ -413,10 +413,10 @@ class Node_Database extends Node ); $query .= "%'"; } - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Name']; $count++; diff --git a/libraries/navigation/Nodes/Node_Event.class.php b/libraries/navigation/Nodes/Node_Event.class.php index dbf55486a2..f3c9e536b0 100644 --- a/libraries/navigation/Nodes/Node_Event.class.php +++ b/libraries/navigation/Nodes/Node_Event.class.php @@ -59,7 +59,7 @@ class Node_Event extends Node $query .= "FROM `INFORMATION_SCHEMA`.`EVENTS` "; $query .= "WHERE `EVENT_SCHEMA`='$db' "; $query .= "AND `EVENT_NAME`='$event' "; - return PMA_DBI_fetchValue($query); + return $GLOBALS['dbi']->fetchValue($query); } } diff --git a/libraries/navigation/Nodes/Node_Function.class.php b/libraries/navigation/Nodes/Node_Function.class.php index 3f5364651d..9f63d63cb5 100644 --- a/libraries/navigation/Nodes/Node_Function.class.php +++ b/libraries/navigation/Nodes/Node_Function.class.php @@ -60,7 +60,7 @@ class Node_Function extends Node $query .= "WHERE `ROUTINE_SCHEMA`='$db' "; $query .= "AND `ROUTINE_NAME`='$routine' "; $query .= "AND `ROUTINE_TYPE`='FUNCTION' "; - return PMA_DBI_fetchValue($query); + return $GLOBALS['dbi']->fetchValue($query); } } diff --git a/libraries/navigation/Nodes/Node_Procedure.class.php b/libraries/navigation/Nodes/Node_Procedure.class.php index 443998a855..6e48ea903e 100644 --- a/libraries/navigation/Nodes/Node_Procedure.class.php +++ b/libraries/navigation/Nodes/Node_Procedure.class.php @@ -60,7 +60,7 @@ class Node_Procedure extends Node $query .= "WHERE `ROUTINE_SCHEMA`='$db' "; $query .= "AND `ROUTINE_NAME`='$routine' "; $query .= "AND `ROUTINE_TYPE`='PROCEDURE' "; - return PMA_DBI_fetchValue($query); + return $GLOBALS['dbi']->fetchValue($query); } } diff --git a/libraries/navigation/Nodes/Node_Table.class.php b/libraries/navigation/Nodes/Node_Table.class.php index 44d9c05371..3555254f17 100644 --- a/libraries/navigation/Nodes/Node_Table.class.php +++ b/libraries/navigation/Nodes/Node_Table.class.php @@ -64,19 +64,19 @@ class Node_Table extends Node $query .= "FROM `INFORMATION_SCHEMA`.`COLUMNS` "; $query .= "WHERE `TABLE_NAME`='$table' "; $query .= "AND `TABLE_SCHEMA`='$db'"; - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW COLUMNS FROM $table FROM $db"; - $retval = (int)PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = (int)$GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; case 'indexes': $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW INDEXES FROM $table FROM $db"; - $retval = (int)PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = (int)$GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); break; case 'triggers': if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { @@ -86,12 +86,12 @@ class Node_Table extends Node $query .= "FROM `INFORMATION_SCHEMA`.`TRIGGERS` "; $query .= "WHERE `EVENT_OBJECT_SCHEMA`='$db' "; $query .= "AND `EVENT_OBJECT_TABLE`='$table'"; - $retval = (int)PMA_DBI_fetchValue($query); + $retval = (int)$GLOBALS['dbi']->fetchValue($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'"; - $retval = (int)PMA_DBI_numRows(PMA_DBI_tryQuery($query)); + $retval = (int)$GLOBALS['dbi']->numRows($GLOBALS['dbi']->tryQuery($query)); } break; default: @@ -128,15 +128,15 @@ class Node_Table extends Node $query .= "AND `TABLE_SCHEMA`='$db' "; $query .= "ORDER BY `COLUMN_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW COLUMNS FROM $table FROM $db"; - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Field']; $count++; @@ -150,10 +150,10 @@ class Node_Table extends Node $db = PMA_Util::backquote($db); $table = PMA_Util::backquote($table); $query = "SHOW INDEXES FROM $table FROM $db"; - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if (! in_array($arr['Key_name'], $retval)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Key_name']; @@ -174,15 +174,15 @@ class Node_Table extends Node $query .= "AND `EVENT_OBJECT_TABLE`='$table' "; $query .= "ORDER BY `TRIGGER_NAME` ASC "; $query .= "LIMIT " . intval($pos) . ", $maxItems"; - $retval = PMA_DBI_fetchResult($query); + $retval = $GLOBALS['dbi']->fetchResult($query); } else { $db = PMA_Util::backquote($db); $table = PMA_Util::sqlAddSlashes($table); $query = "SHOW TRIGGERS FROM $db WHERE `Table` = '$table'"; - $handle = PMA_DBI_tryQuery($query); + $handle = $GLOBALS['dbi']->tryQuery($query); if ($handle !== false) { $count = 0; - while ($arr = PMA_DBI_fetchArray($handle)) { + while ($arr = $GLOBALS['dbi']->fetchArray($handle)) { if ($pos <= 0 && $count < $maxItems) { $retval[] = $arr['Trigger']; $count++; @@ -214,12 +214,12 @@ class Node_Table extends Node $query .= "FROM `INFORMATION_SCHEMA`.`TABLES` "; $query .= "WHERE `TABLE_SCHEMA`='$db' "; $query .= "AND `TABLE_NAME`='$table' "; - $retval = PMA_DBI_fetchValue($query); + $retval = $GLOBALS['dbi']->fetchValue($query); } else { $db = PMA_Util::backquote($db); $query = "SHOW TABLE STATUS FROM $db "; $query .= "WHERE Name = '$table'"; - $arr = PMA_DBI_fetchAssoc(PMA_DBI_tryQuery($query)); + $arr = $GLOBALS['dbi']->fetchAssoc($GLOBALS['dbi']->tryQuery($query)); $retval = $arr['Comment']; } return $retval; diff --git a/libraries/operations.lib.php b/libraries/operations.lib.php index 9ee5828b9d..79da986943 100644 --- a/libraries/operations.lib.php +++ b/libraries/operations.lib.php @@ -294,29 +294,29 @@ function PMA_getHtmlForExportRelationalSchemaView($url_query) */ function PMA_runProcedureAndFunctionDefinitions($db) { - $procedure_names = PMA_DBI_getProceduresOrFunctions($db, 'PROCEDURE'); + $procedure_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE'); if ($procedure_names) { foreach ($procedure_names as $procedure_name) { - PMA_DBI_selectDb($db); - $tmp_query = PMA_DBI_getDefinition( + $GLOBALS['dbi']->selectDb($db); + $tmp_query = $GLOBALS['dbi']->getDefinition( $db, 'PROCEDURE', $procedure_name ); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; - PMA_DBI_selectDb($_REQUEST['newname']); - PMA_DBI_query($tmp_query); + $GLOBALS['dbi']->selectDb($_REQUEST['newname']); + $GLOBALS['dbi']->query($tmp_query); } } - $function_names = PMA_DBI_getProceduresOrFunctions($db, 'FUNCTION'); + $function_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION'); if ($function_names) { foreach ($function_names as $function_name) { - PMA_DBI_selectDb($db); - $tmp_query = PMA_DBI_getDefinition($db, 'FUNCTION', $function_name); + $GLOBALS['dbi']->selectDb($db); + $tmp_query = $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $function_name); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; - PMA_DBI_selectDb($_REQUEST['newname']); - PMA_DBI_query($tmp_query); + $GLOBALS['dbi']->selectDb($_REQUEST['newname']); + $GLOBALS['dbi']->query($tmp_query); } } } @@ -330,7 +330,7 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy() { // lower_case_table_names=1 `DB` becomes `db` if (! PMA_DRIZZLE) { - $lower_case_table_names = PMA_DBI_fetchValue( + $lower_case_table_names = $GLOBALS['dbi']->fetchValue( 'SHOW VARIABLES LIKE "lower_case_table_names"', 0, 1 ); if ($lower_case_table_names === '1') { @@ -347,10 +347,10 @@ function PMA_getSqlQueryAndCreateDbBeforeCopy() $local_query .= ';'; $sql_query = $local_query; // save the original db name because Tracker.class.php which - // may be called under PMA_DBI_query() changes $GLOBALS['db'] + // may be called under $GLOBALS['dbi']->query() changes $GLOBALS['db'] // for some statements, one of which being CREATE DATABASE $original_db = $GLOBALS['db']; - PMA_DBI_query($local_query); + $GLOBALS['dbi']->query($local_query); $GLOBALS['db'] = $original_db; // rebuild the database list because PMA_Table::moveCopy @@ -382,7 +382,7 @@ function PMA_getSqlConstraintsQueryForFullDb( $db, $each_table, "\n", '', false, false ); if ($move && ! empty($sql_drop_foreign_keys)) { - PMA_DBI_query($sql_drop_foreign_keys); + $GLOBALS['dbi']->query($sql_drop_foreign_keys); } // keep the constraint we just dropped if (! empty($sql_constraints)) { @@ -415,8 +415,8 @@ function PMA_getViewsAndCreateSqlViewStandIn( $sql_view_standin = $export_sql_plugin->getTableDefStandIn( $db, $each_table, "\n" ); - PMA_DBI_selectDb($_REQUEST['newname']); - PMA_DBI_query($sql_view_standin); + $GLOBALS['dbi']->selectDb($_REQUEST['newname']); + $GLOBALS['dbi']->query($sql_view_standin); $GLOBALS['sql_query'] .= "\n" . $sql_view_standin; } } @@ -462,7 +462,7 @@ function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db) // keep the triggers from the original db+table // (third param is empty because delimiters are only intended // for importing via the mysql client or our Import feature) - $triggers = PMA_DBI_getTriggers($db, $each_table, ''); + $triggers = $GLOBALS['dbi']->getTriggers($db, $each_table, ''); if (! PMA_Table::moveCopy( $db, $each_table, $_REQUEST['newname'], $each_table, @@ -476,9 +476,9 @@ function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db) } // apply the triggers to the destination db+table if ($triggers) { - PMA_DBI_selectDb($_REQUEST['newname']); + $GLOBALS['dbi']->selectDb($_REQUEST['newname']); foreach ($triggers as $trigger) { - PMA_DBI_query($trigger['create']); + $GLOBALS['dbi']->query($trigger['create']); $GLOBALS['sql_query'] .= "\n" . $trigger['create'] . ';'; } } @@ -511,18 +511,18 @@ function PMA_getSqlQueryForCopyTable($tables_full, $sql_query, $move, $db) */ function PMA_runEventDefinitionsForDb($db) { - $event_names = PMA_DBI_fetchResult( + $event_names = $GLOBALS['dbi']->fetchResult( 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE EVENT_SCHEMA= \'' . PMA_Util::sqlAddSlashes($db, true) . '\';' ); if ($event_names) { foreach ($event_names as $event_name) { - PMA_DBI_selectDb($db); - $tmp_query = PMA_DBI_getDefinition($db, 'EVENT', $event_name); + $GLOBALS['dbi']->selectDb($db); + $tmp_query = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event_name); // collect for later display $GLOBALS['sql_query'] .= "\n" . $tmp_query; - PMA_DBI_selectDb($_REQUEST['newname']); - PMA_DBI_query($tmp_query); + $GLOBALS['dbi']->selectDb($_REQUEST['newname']); + $GLOBALS['dbi']->query($tmp_query); } } } @@ -571,9 +571,9 @@ function PMA_handleTheViews($views, $move, $db) */ function PMA_createAllAccumulatedConstraints() { - PMA_DBI_selectDb($_REQUEST['newname']); + $GLOBALS['dbi']->selectDb($_REQUEST['newname']); foreach ($GLOBALS['sql_constraints_query_full_db'] as $one_query) { - PMA_DBI_query($one_query); + $GLOBALS['dbi']->query($one_query); // and prepare to display them $GLOBALS['sql_query'] .= "\n" . $one_query; } @@ -1424,7 +1424,7 @@ function PMA_getQueryAndResultForReorderingTable() $sql_query .= ' DESC'; } $sql_query .= ';'; - $result = PMA_DBI_query($sql_query); + $result = $GLOBALS['dbi']->query($sql_query); return array($sql_query, $result); } @@ -1573,7 +1573,7 @@ function PMA_setGlobalVariablesForEngine($tbl_storage_engine) function PMA_getWarningMessagesArray() { $warning_messages = array(); - foreach (PMA_DBI_getWarnings() as $warning) { + foreach ($GLOBALS['dbi']->getWarnings() as $warning) { // In MariaDB 5.1.44, when altering a table from Maria to MyISAM // and if TRANSACTIONAL was set, the system reports an error; // I discussed with a Maria developer and he agrees that this @@ -1604,7 +1604,7 @@ function PMA_getQueryAndResultForPartition() . $_REQUEST['partition_operation'] . ' PARTITION ' . $_REQUEST['partition_name'] . ';'; - $result = PMA_DBI_query($sql_query); + $result = $GLOBALS['dbi']->query($sql_query); return array($sql_query, $result); } diff --git a/libraries/plugins/auth/AuthenticationConfig.class.php b/libraries/plugins/auth/AuthenticationConfig.class.php index 07ad7cb553..b33ebe570a 100644 --- a/libraries/plugins/auth/AuthenticationConfig.class.php +++ b/libraries/plugins/auth/AuthenticationConfig.class.php @@ -68,7 +68,7 @@ class AuthenticationConfig extends AuthenticationPlugin */ public function authFails() { - $conn_error = PMA_DBI_getError(); + $conn_error = $GLOBALS['dbi']->getError(); if (! $conn_error) { $conn_error = __('Cannot connect: invalid settings.'); } diff --git a/libraries/plugins/auth/AuthenticationCookie.class.php b/libraries/plugins/auth/AuthenticationCookie.class.php index aeaae83bc5..a73217a6e5 100644 --- a/libraries/plugins/auth/AuthenticationCookie.class.php +++ b/libraries/plugins/auth/AuthenticationCookie.class.php @@ -287,7 +287,7 @@ class AuthenticationCookie extends AuthenticationPlugin * * this function DOES NOT check authentication - it just checks/provides * authentication credentials required to connect to the MySQL server - * usually with PMA_DBI_connect() + * usually with $GLOBALS['dbi']->connect() * * it returns false if something is missing - which usually leads to * auth() which displays login form @@ -590,7 +590,7 @@ class AuthenticationCookie extends AuthenticationPlugin __('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity'] ); - } elseif (PMA_DBI_getError()) { + } elseif ($GLOBALS['dbi']->getError()) { $conn_error = '#' . $GLOBALS['errno'] . ' ' . __('Cannot log in to the MySQL server'); } else { diff --git a/libraries/plugins/auth/AuthenticationHttp.class.php b/libraries/plugins/auth/AuthenticationHttp.class.php index f81ab92a55..5d1eb8e261 100644 --- a/libraries/plugins/auth/AuthenticationHttp.class.php +++ b/libraries/plugins/auth/AuthenticationHttp.class.php @@ -225,7 +225,7 @@ class AuthenticationHttp extends AuthenticationPlugin */ public function authFails() { - $error = PMA_DBI_getError(); + $error = $GLOBALS['dbi']->getError(); if ($error && $GLOBALS['errno'] != 1045) { PMA_fatalError($error); } else { diff --git a/libraries/plugins/auth/AuthenticationSignon.class.php b/libraries/plugins/auth/AuthenticationSignon.class.php index ee1cf364b7..11ab439889 100644 --- a/libraries/plugins/auth/AuthenticationSignon.class.php +++ b/libraries/plugins/auth/AuthenticationSignon.class.php @@ -256,9 +256,9 @@ class AuthenticationSignon extends AuthenticationPlugin __('No activity within %s seconds; please log in again'), $GLOBALS['cfg']['LoginCookieValidity'] ); - } elseif (PMA_DBI_getError()) { + } elseif ($GLOBALS['dbi']->getError()) { $_SESSION['PMA_single_signon_error_message'] = PMA_sanitize( - PMA_DBI_getError() + $GLOBALS['dbi']->getError() ); } else { $_SESSION['PMA_single_signon_error_message'] = __( diff --git a/libraries/plugins/export/ExportCodegen.class.php b/libraries/plugins/export/ExportCodegen.class.php index fa007d5662..4495e7ee4d 100644 --- a/libraries/plugins/export/ExportCodegen.class.php +++ b/libraries/plugins/export/ExportCodegen.class.php @@ -244,7 +244,7 @@ class ExportCodegen extends ExportPlugin { $lines = array(); - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( sprintf( 'DESC %s.%s', PMA_Util::backquote($db), PMA_Util::backquote($table) @@ -252,10 +252,10 @@ class ExportCodegen extends ExportPlugin ); if ($result) { $tableProperties = array(); - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $tableProperties[] = new TableProperty($row); } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); $lines[] = 'using System;'; $lines[] = 'using System.Collections;'; $lines[] = 'using System.Collections.Generic;'; @@ -336,14 +336,14 @@ class ExportCodegen extends ExportPlugin $lines[] = ' <class ' . 'name="' . ExportCodegen::cgMakeIdentifier($table) . '" ' . 'table="' . ExportCodegen::cgMakeIdentifier($table) . '">'; - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( sprintf( "DESC %s.%s", PMA_Util::backquote($db), PMA_Util::backquote($table) ) ); if ($result) { - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $tableProperty = new TableProperty($row); if ($tableProperty->isPK()) { $lines[] = $tableProperty->formatXml( @@ -365,7 +365,7 @@ class ExportCodegen extends ExportPlugin ); } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } $lines[] = ' </class>'; $lines[] = '</hibernate-mapping>'; diff --git a/libraries/plugins/export/ExportCsv.class.php b/libraries/plugins/export/ExportCsv.class.php index a644a63068..904026c93a 100644 --- a/libraries/plugins/export/ExportCsv.class.php +++ b/libraries/plugins/export/ExportCsv.class.php @@ -246,21 +246,21 @@ class ExportCsv extends ExportPlugin global $what, $csv_terminated, $csv_separator, $csv_enclosed, $csv_escaped; // Gets the data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_numFields($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $fields_cnt = $GLOBALS['dbi']->numFields($result); // If required, get fields name at the first line if (isset($GLOBALS['csv_columns'])) { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { if ($csv_enclosed == '') { - $schema_insert .= stripslashes(PMA_DBI_fieldName($result, $i)); + $schema_insert .= stripslashes($GLOBALS['dbi']->fieldName($result, $i)); } else { $schema_insert .= $csv_enclosed . str_replace( $csv_enclosed, $csv_escaped . $csv_enclosed, - stripslashes(PMA_DBI_fieldName($result, $i)) + stripslashes($GLOBALS['dbi']->fieldName($result, $i)) ) . $csv_enclosed; } @@ -273,7 +273,7 @@ class ExportCsv extends ExportPlugin } // end if // Format the data - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (! isset($row[$j]) || is_null($row[$j])) { @@ -336,7 +336,7 @@ class ExportCsv extends ExportPlugin return false; } } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } diff --git a/libraries/plugins/export/ExportHtmlword.class.php b/libraries/plugins/export/ExportHtmlword.class.php index df258ae051..7907e41939 100644 --- a/libraries/plugins/export/ExportHtmlword.class.php +++ b/libraries/plugins/export/ExportHtmlword.class.php @@ -212,8 +212,8 @@ class ExportHtmlword extends ExportPlugin } // Gets the data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_numFields($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $fields_cnt = $GLOBALS['dbi']->numFields($result); // If required, get fields name at the first line if (isset($GLOBALS['htmlword_columns'])) { @@ -221,7 +221,7 @@ class ExportHtmlword extends ExportPlugin for ($i = 0; $i < $fields_cnt; $i++) { $schema_insert .= '<td class="print"><strong>' . htmlspecialchars( - stripslashes(PMA_DBI_fieldName($result, $i)) + stripslashes($GLOBALS['dbi']->fieldName($result, $i)) ) . '</strong></td>'; } // end for @@ -232,7 +232,7 @@ class ExportHtmlword extends ExportPlugin } // end if // Format the data - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $schema_insert = '<tr class="print-category">'; for ($j = 0; $j < $fields_cnt; $j++) { if (! isset($row[$j]) || is_null($row[$j])) { @@ -251,7 +251,7 @@ class ExportHtmlword extends ExportPlugin return false; } } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); if (! PMA_exportOutputHandler('</table>')) { return false; } @@ -290,14 +290,14 @@ class ExportHtmlword extends ExportPlugin * Get the unique keys in the view */ $unique_keys = array(); - $keys = PMA_DBI_getTableIndexes($db, $view); + $keys = $GLOBALS['dbi']->getTableIndexes($db, $view); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } - $columns = PMA_DBI_getColumns($db, $view); + $columns = $GLOBALS['dbi']->getColumns($db, $view); foreach ($columns as $column) { $schema_insert .= $this->formatOneColumnDefinition( $column, @@ -353,7 +353,7 @@ class ExportHtmlword extends ExportPlugin /** * Gets fields properties */ - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations if ($do_relation && ! empty($cfgRelation['relation'])) { @@ -418,12 +418,12 @@ class ExportHtmlword extends ExportPlugin } $schema_insert .= '</tr>'; - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); /** * Get the unique keys in the table */ $unique_keys = array(); - $keys = PMA_DBI_getTableIndexes($db, $table); + $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; @@ -486,7 +486,7 @@ class ExportHtmlword extends ExportPlugin $dump .= '<td class="print"><strong>' . __('Definition') . '</strong></td>'; $dump .= '</tr>'; - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); foreach ($triggers as $trigger) { $dump .= '<tr class="print-category">'; @@ -557,7 +557,7 @@ class ExportHtmlword extends ExportPlugin break; case 'triggers': $dump = ''; - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); if ($triggers) { $dump .= '<h2>' . __('Triggers') . ' ' . htmlspecialchars($table) diff --git a/libraries/plugins/export/ExportJson.class.php b/libraries/plugins/export/ExportJson.class.php index 683e37765d..49847eac3d 100644 --- a/libraries/plugins/export/ExportJson.class.php +++ b/libraries/plugins/export/ExportJson.class.php @@ -158,20 +158,20 @@ class ExportJson extends ExportPlugin */ public function exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $columns_cnt = PMA_DBI_numFields($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $columns_cnt = $GLOBALS['dbi']->numFields($result); // Get field information - $fields_meta = PMA_DBI_getFieldsMeta($result); + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = stripslashes(PMA_DBI_fieldName($result, $i)); + $columns[$i] = stripslashes($GLOBALS['dbi']->fieldName($result, $i)); } unset($i); $buffer = ''; $record_cnt = 0; - while ($record = PMA_DBI_fetchRow($result)) { + while ($record = $GLOBALS['dbi']->fetchRow($result)) { $record_cnt++; @@ -214,7 +214,7 @@ class ExportJson extends ExportPlugin return false; } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } } diff --git a/libraries/plugins/export/ExportLatex.class.php b/libraries/plugins/export/ExportLatex.class.php index 295351d5bc..4f5fe04dc6 100644 --- a/libraries/plugins/export/ExportLatex.class.php +++ b/libraries/plugins/export/ExportLatex.class.php @@ -290,11 +290,11 @@ class ExportLatex extends ExportPlugin */ public function exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_DBI_tryQuery($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $result = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $columns_cnt = PMA_DBI_numFields($result); + $columns_cnt = $GLOBALS['dbi']->numFields($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = PMA_DBI_fieldName($result, $i); + $columns[$i] = $GLOBALS['dbi']->fieldName($result, $i); } unset($i); @@ -370,7 +370,7 @@ class ExportLatex extends ExportPlugin } // print the whole table - while ($record = PMA_DBI_fetchAssoc($result)) { + while ($record = $GLOBALS['dbi']->fetchAssoc($result)) { $buffer = ''; // print each row for ($i = 0; $i < $columns_cnt; $i++) { @@ -403,7 +403,7 @@ class ExportLatex extends ExportPlugin return false; } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } // end getTableLaTeX @@ -452,7 +452,7 @@ class ExportLatex extends ExportPlugin * Get the unique keys in the table */ $unique_keys = array(); - $keys = PMA_DBI_getTableIndexes($db, $table); + $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; @@ -462,7 +462,7 @@ class ExportLatex extends ExportPlugin /** * Gets fields properties */ - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations if ($do_relation && ! empty($cfgRelation['relation'])) { @@ -563,7 +563,7 @@ class ExportLatex extends ExportPlugin return false; } - $fields = PMA_DBI_getColumns($db, $table); + $fields = $GLOBALS['dbi']->getColumns($db, $table); foreach ($fields as $row) { $extracted_columnspec = PMA_Util::extractColumnSpec( diff --git a/libraries/plugins/export/ExportMediawiki.class.php b/libraries/plugins/export/ExportMediawiki.class.php index bb48814ce3..e39442315d 100644 --- a/libraries/plugins/export/ExportMediawiki.class.php +++ b/libraries/plugins/export/ExportMediawiki.class.php @@ -202,7 +202,7 @@ class ExportMediawiki extends ExportPlugin ) { switch($export_mode) { case 'create_table': - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); $columns = array_values($columns); $row_cnt = count($columns); @@ -300,7 +300,7 @@ class ExportMediawiki extends ExportPlugin // Add the table headers if ($GLOBALS['mediawiki_headers']) { // Get column names - $column_names = PMA_DBI_getColumnNames($db, $table); + $column_names = $GLOBALS['dbi']->getColumnNames($db, $table); // Add column names as table headers if ( ! is_null($column_names) ) { @@ -315,10 +315,10 @@ class ExportMediawiki extends ExportPlugin } // Get the table data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_numFields($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $fields_cnt = $GLOBALS['dbi']->numFields($result); - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $output .= "|-" . $this->_exportCRLF(); // Use '|' for separating table columns diff --git a/libraries/plugins/export/ExportOds.class.php b/libraries/plugins/export/ExportOds.class.php index f9183dc1e9..075378f1c5 100644 --- a/libraries/plugins/export/ExportOds.class.php +++ b/libraries/plugins/export/ExportOds.class.php @@ -226,12 +226,12 @@ class ExportOds extends ExportPlugin global $what; // Gets the data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_numFields($result); - $fields_meta = PMA_DBI_getFieldsMeta($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $fields_cnt = $GLOBALS['dbi']->numFields($result); + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); $field_flags = array(); for ($j = 0; $j < $fields_cnt; $j++) { - $field_flags[$j] = PMA_DBI_fieldFlags($result, $j); + $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j); } $GLOBALS['ods_buffer'] .= @@ -245,7 +245,7 @@ class ExportOds extends ExportPlugin '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars( - stripslashes(PMA_DBI_fieldName($result, $i)) + stripslashes($GLOBALS['dbi']->fieldName($result, $i)) ) . '</text:p>' . '</table:table-cell>'; @@ -254,7 +254,7 @@ class ExportOds extends ExportPlugin } // end if // Format the data - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $GLOBALS['ods_buffer'] .= '<table:table-row>'; for ($j = 0; $j < $fields_cnt; $j++) { if (! isset($row[$j]) || is_null($row[$j])) { @@ -324,7 +324,7 @@ class ExportOds extends ExportPlugin } // end for $GLOBALS['ods_buffer'] .= '</table:table-row>'; } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); $GLOBALS['ods_buffer'] .= '</table:table>'; diff --git a/libraries/plugins/export/ExportOdt.class.php b/libraries/plugins/export/ExportOdt.class.php index 3e2265f4bb..814eb5dadc 100644 --- a/libraries/plugins/export/ExportOdt.class.php +++ b/libraries/plugins/export/ExportOdt.class.php @@ -244,12 +244,12 @@ class ExportOdt extends ExportPlugin global $what; // Gets the data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_numFields($result); - $fields_meta = PMA_DBI_getFieldsMeta($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $fields_cnt = $GLOBALS['dbi']->numFields($result); + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); $field_flags = array(); for ($j = 0; $j < $fields_cnt; $j++) { - $field_flags[$j] = PMA_DBI_fieldFlags($result, $j); + $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j); } $GLOBALS['odt_buffer'] .= @@ -270,7 +270,7 @@ class ExportOdt extends ExportPlugin '<table:table-cell office:value-type="string">' . '<text:p>' . htmlspecialchars( - stripslashes(PMA_DBI_fieldName($result, $i)) + stripslashes($GLOBALS['dbi']->fieldName($result, $i)) ) . '</text:p>' . '</table:table-cell>'; @@ -279,7 +279,7 @@ class ExportOdt extends ExportPlugin } // end if // Format the data - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $GLOBALS['odt_buffer'] .= '<table:table-row>'; for ($j = 0; $j < $fields_cnt; $j++) { if (! isset($row[$j]) || is_null($row[$j])) { @@ -319,7 +319,7 @@ class ExportOdt extends ExportPlugin } // end for $GLOBALS['odt_buffer'] .= '</table:table-row>'; } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); $GLOBALS['odt_buffer'] .= '</table:table>'; @@ -340,7 +340,7 @@ class ExportOdt extends ExportPlugin /** * Gets fields properties */ - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); /** * Displays the table structure @@ -368,7 +368,7 @@ class ExportOdt extends ExportPlugin . '</table:table-cell>' . '</table:table-row>'; - $columns = PMA_DBI_getColumns($db, $view); + $columns = $GLOBALS['dbi']->getColumns($db, $view); foreach ($columns as $column) { $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column); $GLOBALS['odt_buffer'] .= '</table:table-row>'; @@ -416,7 +416,7 @@ class ExportOdt extends ExportPlugin /** * Gets fields properties */ - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations if ($do_relation && ! empty($cfgRelation['relation'])) { @@ -483,7 +483,7 @@ class ExportOdt extends ExportPlugin } $GLOBALS['odt_buffer'] .= '</table:table-row>'; - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); foreach ($columns as $column) { $field_name = $column['Field']; $GLOBALS['odt_buffer'] .= $this->formatOneColumnDefinition($column); @@ -569,7 +569,7 @@ class ExportOdt extends ExportPlugin . '</table:table-cell>' . '</table:table-row>'; - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); foreach ($triggers as $trigger) { $GLOBALS['odt_buffer'] .= '<table:table-row>'; @@ -647,7 +647,7 @@ class ExportOdt extends ExportPlugin ); break; case 'triggers': - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); if ($triggers) { $GLOBALS['odt_buffer'] .= '<text:h text:outline-level="2" text:style-name="Heading_2"' diff --git a/libraries/plugins/export/ExportPhparray.class.php b/libraries/plugins/export/ExportPhparray.class.php index 550c0b6101..8c3ac0ceec 100644 --- a/libraries/plugins/export/ExportPhparray.class.php +++ b/libraries/plugins/export/ExportPhparray.class.php @@ -163,11 +163,11 @@ class ExportPhparray extends ExportPlugin */ public function exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $columns_cnt = PMA_DBI_numFields($result); + $columns_cnt = $GLOBALS['dbi']->numFields($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = stripslashes(PMA_DBI_fieldName($result, $i)); + $columns[$i] = stripslashes($GLOBALS['dbi']->fieldName($result, $i)); } unset($i); @@ -197,7 +197,7 @@ class ExportPhparray extends ExportPlugin . PMA_Util::backquote($table) . $crlf; $buffer .= '$' . $tablefixed . ' = array('; - while ($record = PMA_DBI_fetchRow($result)) { + while ($record = $GLOBALS['dbi']->fetchRow($result)) { $record_cnt++; if ($record_cnt == 1) { @@ -220,7 +220,7 @@ class ExportPhparray extends ExportPlugin return false; } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } } diff --git a/libraries/plugins/export/ExportSql.class.php b/libraries/plugins/export/ExportSql.class.php index 6865a66719..8b969191cb 100644 --- a/libraries/plugins/export/ExportSql.class.php +++ b/libraries/plugins/export/ExportSql.class.php @@ -149,7 +149,7 @@ class ExportSql extends ExportPlugin $generalOptions->addProperty($leaf); // compatibility maximization - $compats = PMA_DBI_getCompatibilities(); + $compats = $GLOBALS['dbi']->getCompatibilities(); if (count($compats) > 0) { $values = array(); foreach ($compats as $val) { @@ -444,8 +444,8 @@ class ExportSql extends ExportPlugin $text = ''; $delimiter = '$$'; - $procedure_names = PMA_DBI_getProceduresOrFunctions($db, 'PROCEDURE'); - $function_names = PMA_DBI_getProceduresOrFunctions($db, 'FUNCTION'); + $procedure_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE'); + $function_names = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION'); if ($procedure_names || $function_names) { $text .= $crlf @@ -464,7 +464,7 @@ class ExportSql extends ExportPlugin . PMA_Util::backquote($procedure_name) . $delimiter . $crlf; } - $text .= PMA_DBI_getDefinition($db, 'PROCEDURE', $procedure_name) + $text .= $GLOBALS['dbi']->getDefinition($db, 'PROCEDURE', $procedure_name) . $delimiter . $crlf . $crlf; } } @@ -481,7 +481,7 @@ class ExportSql extends ExportPlugin . PMA_Util::backquote($function_name) . $delimiter . $crlf; } - $text .= PMA_DBI_getDefinition($db, 'FUNCTION', $function_name) + $text .= $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $function_name) . $delimiter . $crlf . $crlf; } } @@ -569,7 +569,7 @@ class ExportSql extends ExportPlugin /* Restore timezone */ if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) { - PMA_DBI_query('SET time_zone = "' . $GLOBALS['old_tz'] . '"'); + $GLOBALS['dbi']->query('SET time_zone = "' . $GLOBALS['old_tz'] . '"'); } return PMA_exportOutputHandler($foot); @@ -591,7 +591,7 @@ class ExportSql extends ExportPlugin if ($tmp_compat == 'NONE') { $tmp_compat = ''; } - PMA_DBI_tryQuery('SET SQL_MODE="' . $tmp_compat . '"'); + $GLOBALS['dbi']->tryQuery('SET SQL_MODE="' . $tmp_compat . '"'); unset($tmp_compat); } $head = $this->_exportComment('phpMyAdmin SQL Dump') @@ -648,8 +648,8 @@ class ExportSql extends ExportPlugin /* Change timezone if we should export timestamps in UTC */ if (isset($GLOBALS['sql_utc_time']) && $GLOBALS['sql_utc_time']) { $head .= 'SET time_zone = "+00:00";' . $crlf; - $GLOBALS['old_tz'] = PMA_DBI_fetchValue('SELECT @@session.time_zone'); - PMA_DBI_query('SET time_zone = "+00:00"'); + $GLOBALS['old_tz'] = $GLOBALS['dbi']->fetchValue('SELECT @@session.time_zone'); + $GLOBALS['dbi']->query('SET time_zone = "+00:00"'); } $head .= $this->_possibleCRLF(); @@ -791,7 +791,7 @@ class ExportSql extends ExportPlugin $delimiter = '$$'; if (PMA_MYSQL_INT_VERSION > 50100) { - $event_names = PMA_DBI_fetchResult( + $event_names = $GLOBALS['dbi']->fetchResult( 'SELECT EVENT_NAME FROM information_schema.EVENTS WHERE' . ' EVENT_SCHEMA= \'' . PMA_Util::sqlAddSlashes($db, true) @@ -816,7 +816,7 @@ class ExportSql extends ExportPlugin . PMA_Util::backquote($event_name) . $delimiter . $crlf; } - $text .= PMA_DBI_getDefinition($db, 'EVENT', $event_name) + $text .= $GLOBALS['dbi']->getDefinition($db, 'EVENT', $event_name) . $delimiter . $crlf . $crlf; } @@ -857,7 +857,7 @@ class ExportSql extends ExportPlugin } $create_query .= PMA_Util::backquote($view) . ' (' . $crlf; $tmp = array(); - $columns = PMA_DBI_getColumnsFull($db, $view); + $columns = $GLOBALS['dbi']->getColumnsFull($db, $view); foreach ($columns as $column_name => $definition) { $tmp[] = PMA_Util::backquote($column_name) . ' ' . $definition['Type'] . $crlf; @@ -903,16 +903,16 @@ class ExportSql extends ExportPlugin $compat = 'NONE'; } - // need to use PMA_DBI_QUERY_STORE with PMA_DBI_numRows() in mysqli - $result = PMA_DBI_query( + // need to use PMA_DBI_QUERY_STORE with $GLOBALS['dbi']->numRows() in mysqli + $result = $GLOBALS['dbi']->query( 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\'', null, PMA_DBI_QUERY_STORE ); if ($result != false) { - if (PMA_DBI_numRows($result) > 0) { - $tmpres = PMA_DBI_fetchAssoc($result); + if ($GLOBALS['dbi']->numRows($result) > 0) { + $tmpres = $GLOBALS['dbi']->fetchAssoc($result); if (PMA_DRIZZLE && $show_dates) { // Drizzle doesn't give Create_time and Update_time in // SHOW TABLE STATUS, add it @@ -924,7 +924,7 @@ class ExportSql extends ExportPlugin . PMA_Util::sqlAddSlashes($db) . "' AND TABLE_NAME = '" . PMA_Util::sqlAddSlashes($table) . "'"; - $tmpres = array_merge(PMA_DBI_fetchSingleRow($sql), $tmpres); + $tmpres = array_merge($GLOBALS['dbi']->fetchSingleRow($sql), $tmpres); } // Here we optionally add the AUTO_INCREMENT next value, // but starting with MySQL 5.0.24, the clause is already included @@ -977,7 +977,7 @@ class ExportSql extends ExportPlugin $new_crlf = $this->_exportComment() . $crlf; } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } $schema_create .= $new_crlf; @@ -994,9 +994,9 @@ class ExportSql extends ExportPlugin // Drizzle always quotes names if (! PMA_DRIZZLE) { if ($sql_backquotes) { - PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 1'); + $GLOBALS['dbi']->query('SET SQL_QUOTE_SHOW_CREATE = 1'); } else { - PMA_DBI_query('SET SQL_QUOTE_SHOW_CREATE = 0'); + $GLOBALS['dbi']->query('SET SQL_QUOTE_SHOW_CREATE = 0'); } } @@ -1004,23 +1004,23 @@ class ExportSql extends ExportPlugin // because SHOW CREATE TABLE returns only one row, and we free the // results below. Nonetheless, we got 2 user reports about this // (see bug 1562533) so I removed the unbuffered mode. - // $result = PMA_DBI_query('SHOW CREATE TABLE ' . backquote($db) + // $result = $GLOBALS['dbi']->query('SHOW CREATE TABLE ' . backquote($db) // . '.' . backquote($table), null, PMA_DBI_QUERY_UNBUFFERED); // // Note: SHOW CREATE TABLE, at least in MySQL 5.1.23, does not // produce a displayable result for the default value of a BIT // column, nor does the mysqldump command. See MySQL bug 35796 - $result = PMA_DBI_tryQuery( + $result = $GLOBALS['dbi']->tryQuery( 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table) ); // an error can happen, for example the table is crashed - $tmp_error = PMA_DBI_getError(); + $tmp_error = $GLOBALS['dbi']->getError(); if ($tmp_error) { return $this->_exportComment(__('in use') . '(' . $tmp_error . ')'); } - if ($result != false && ($row = PMA_DBI_fetchRow($result))) { + if ($result != false && ($row = $GLOBALS['dbi']->fetchRow($result))) { $create_query = $row[1]; unset($row); @@ -1295,7 +1295,7 @@ class ExportSql extends ExportPlugin $schema_create .= ($compat != 'MSSQL') ? $auto_increment : ''; - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return $schema_create . ($add_semicolon ? ';' . $crlf : ''); } // end of the 'getTableDef()' function @@ -1460,7 +1460,7 @@ class ExportSql extends ExportPlugin break; case 'triggers': $dump = ''; - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); if ($triggers) { $dump .= $this->_possibleCRLF() . $this->_exportComment() @@ -1557,9 +1557,9 @@ class ExportSql extends ExportPlugin // are used, we did not get the true column name in case of aliases) $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($sql_query)); - $result = PMA_DBI_tryQuery($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $result = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); // a possible error: the table has crashed - $tmp_error = PMA_DBI_getError(); + $tmp_error = $GLOBALS['dbi']->getError(); if ($tmp_error) { return PMA_exportOutputHandler( $this->_exportComment( @@ -1569,13 +1569,13 @@ class ExportSql extends ExportPlugin } if ($result != false) { - $fields_cnt = PMA_DBI_numFields($result); + $fields_cnt = $GLOBALS['dbi']->numFields($result); // Get field information - $fields_meta = PMA_DBI_getFieldsMeta($result); + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); $field_flags = array(); for ($j = 0; $j < $fields_cnt; $j++) { - $field_flags[$j] = PMA_DBI_fieldFlags($result, $j); + $field_flags[$j] = $GLOBALS['dbi']->fieldFlags($result, $j); } for ($j = 0; $j < $fields_cnt; $j++) { @@ -1697,7 +1697,7 @@ class ExportSql extends ExportPlugin $separator = ';'; } - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { if ($current_row == 0) { $head = $this->_possibleCRLF() . $this->_exportComment() @@ -1869,7 +1869,7 @@ class ExportSql extends ExportPlugin } } } // end if ($result != false) - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } // end of the 'exportData()' function diff --git a/libraries/plugins/export/ExportTexytext.class.php b/libraries/plugins/export/ExportTexytext.class.php index 0134c5656b..ccda37e2bb 100644 --- a/libraries/plugins/export/ExportTexytext.class.php +++ b/libraries/plugins/export/ExportTexytext.class.php @@ -188,8 +188,8 @@ class ExportTexytext extends ExportPlugin } // Gets the data from the database - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $fields_cnt = PMA_DBI_numFields($result); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $fields_cnt = $GLOBALS['dbi']->numFields($result); // If required, get fields name at the first line if (isset($GLOBALS[$what . '_columns'])) { @@ -197,7 +197,7 @@ class ExportTexytext extends ExportPlugin for ($i = 0; $i < $fields_cnt; $i++) { $text_output .= '|' . htmlspecialchars( - stripslashes(PMA_DBI_fieldName($result, $i)) + stripslashes($GLOBALS['dbi']->fieldName($result, $i)) ); } // end for $text_output .= "\n|------\n"; @@ -207,7 +207,7 @@ class ExportTexytext extends ExportPlugin } // end if // Format the data - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $text_output = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (! isset($row[$j]) || is_null($row[$j])) { @@ -227,7 +227,7 @@ class ExportTexytext extends ExportPlugin return false; } } // end while - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } @@ -249,7 +249,7 @@ class ExportTexytext extends ExportPlugin * Get the unique keys in the table */ $unique_keys = array(); - $keys = PMA_DBI_getTableIndexes($db, $view); + $keys = $GLOBALS['dbi']->getTableIndexes($db, $view); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; @@ -259,7 +259,7 @@ class ExportTexytext extends ExportPlugin /** * Gets fields properties */ - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); /** * Displays the table structure @@ -272,7 +272,7 @@ class ExportTexytext extends ExportPlugin . '|' . __('Default') . "\n|------\n"; - $columns = PMA_DBI_getColumns($db, $view); + $columns = $GLOBALS['dbi']->getColumns($db, $view); foreach ($columns as $column) { $text_output .= $this->formatOneColumnDefinition($column, $unique_keys); $text_output .= "\n"; @@ -323,7 +323,7 @@ class ExportTexytext extends ExportPlugin * Get the unique keys in the table */ $unique_keys = array(); - $keys = PMA_DBI_getTableIndexes($db, $table); + $keys = $GLOBALS['dbi']->getTableIndexes($db, $table); foreach ($keys as $key) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; @@ -333,7 +333,7 @@ class ExportTexytext extends ExportPlugin /** * Gets fields properties */ - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); // Check if we can use Relations if ($do_relation && ! empty($cfgRelation['relation'])) { @@ -383,7 +383,7 @@ class ExportTexytext extends ExportPlugin } $text_output .= "\n|------\n"; - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); foreach ($columns as $column) { $text_output .= $this->formatOneColumnDefinition($column, $unique_keys); $field_name = $column['Field']; @@ -437,7 +437,7 @@ class ExportTexytext extends ExportPlugin $dump .= '|' . __('Definition'); $dump .= "\n|------\n"; - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); foreach ($triggers as $trigger) { $dump .= '|' . $trigger['name']; @@ -501,7 +501,7 @@ class ExportTexytext extends ExportPlugin break; case 'triggers': $dump = ''; - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); if ($triggers) { $dump .= '== ' . __('Triggers') . ' ' .$table . "\n\n"; $dump .= $this->getTriggers($db, $table); diff --git a/libraries/plugins/export/ExportXml.class.php b/libraries/plugins/export/ExportXml.class.php index 712463d12b..73a07fb58f 100644 --- a/libraries/plugins/export/ExportXml.class.php +++ b/libraries/plugins/export/ExportXml.class.php @@ -207,7 +207,7 @@ class ExportXml extends ExportPlugin if ($export_struct) { if (PMA_DRIZZLE) { - $result = PMA_DBI_fetchResult( + $result = $GLOBALS['dbi']->fetchResult( "SELECT 'utf8' AS DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME @@ -216,7 +216,7 @@ class ExportXml extends ExportPlugin . PMA_Util::sqlAddSlashes($db) . "'" ); } else { - $result = PMA_DBI_fetchResult( + $result = $GLOBALS['dbi']->fetchResult( 'SELECT `DEFAULT_CHARACTER_SET_NAME`, `DEFAULT_COLLATION_NAME`' . ' FROM `information_schema`.`SCHEMATA` WHERE `SCHEMA_NAME`' . ' = \''.PMA_Util::sqlAddSlashes($db).'\' LIMIT 1' @@ -239,7 +239,7 @@ class ExportXml extends ExportPlugin foreach ($tables as $table) { // Export tables and views - $result = PMA_DBI_fetchResult( + $result = $GLOBALS['dbi']->fetchResult( 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0 @@ -275,7 +275,7 @@ class ExportXml extends ExportPlugin && $GLOBALS['xml_export_triggers'] ) { // Export triggers - $triggers = PMA_DBI_getTriggers($db, $table); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table); if ($triggers) { foreach ($triggers as $trigger) { $code = $trigger['create']; @@ -301,14 +301,14 @@ class ExportXml extends ExportPlugin && $GLOBALS['xml_export_functions'] ) { // Export functions - $functions = PMA_DBI_getProceduresOrFunctions($db, 'FUNCTION'); + $functions = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'FUNCTION'); if ($functions) { foreach ($functions as $function) { $head .= ' <pma:function name="' . $function . '">' . $crlf; // Do some formatting - $sql = PMA_DBI_getDefinition($db, 'FUNCTION', $function); + $sql = $GLOBALS['dbi']->getDefinition($db, 'FUNCTION', $function); $sql = rtrim($sql); $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); @@ -326,14 +326,14 @@ class ExportXml extends ExportPlugin && $GLOBALS['xml_export_procedures'] ) { // Export procedures - $procedures = PMA_DBI_getProceduresOrFunctions($db, 'PROCEDURE'); + $procedures = $GLOBALS['dbi']->getProceduresOrFunctions($db, 'PROCEDURE'); if ($procedures) { foreach ($procedures as $procedure) { $head .= ' <pma:procedure name="' . $procedure . '">' . $crlf; // Do some formatting - $sql = PMA_DBI_getDefinition($db, 'PROCEDURE', $procedure); + $sql = $GLOBALS['dbi']->getDefinition($db, 'PROCEDURE', $procedure); $sql = rtrim($sql); $sql = " " . htmlspecialchars($sql); $sql = str_replace("\n", "\n ", $sql); @@ -445,12 +445,12 @@ class ExportXml extends ExportPlugin if (isset($GLOBALS['xml_export_contents']) && $GLOBALS['xml_export_contents'] ) { - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $columns_cnt = PMA_DBI_numFields($result); + $columns_cnt = $GLOBALS['dbi']->numFields($result); $columns = array(); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = stripslashes(PMA_DBI_fieldName($result, $i)); + $columns[$i] = stripslashes($GLOBALS['dbi']->fieldName($result, $i)); } unset($i); @@ -459,7 +459,7 @@ class ExportXml extends ExportPlugin return false; } - while ($record = PMA_DBI_fetchRow($result)) { + while ($record = $GLOBALS['dbi']->fetchRow($result)) { $buffer = ' <table name="' . htmlspecialchars($table) . '">' . $crlf; for ($i = 0; $i < $columns_cnt; $i++) { @@ -479,7 +479,7 @@ class ExportXml extends ExportPlugin return false; } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } return true; diff --git a/libraries/plugins/export/ExportYaml.class.php b/libraries/plugins/export/ExportYaml.class.php index 06b7856e52..0edc8200c6 100644 --- a/libraries/plugins/export/ExportYaml.class.php +++ b/libraries/plugins/export/ExportYaml.class.php @@ -156,17 +156,17 @@ class ExportYaml extends ExportPlugin */ public function exportData($db, $table, $crlf, $error_url, $sql_query) { - $result = PMA_DBI_query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); + $result = $GLOBALS['dbi']->query($sql_query, null, PMA_DBI_QUERY_UNBUFFERED); - $columns_cnt = PMA_DBI_numFields($result); + $columns_cnt = $GLOBALS['dbi']->numFields($result); for ($i = 0; $i < $columns_cnt; $i++) { - $columns[$i] = stripslashes(PMA_DBI_fieldName($result, $i)); + $columns[$i] = stripslashes($GLOBALS['dbi']->fieldName($result, $i)); } unset($i); $buffer = ''; $record_cnt = 0; - while ($record = PMA_DBI_fetchRow($result)) { + while ($record = $GLOBALS['dbi']->fetchRow($result)) { $record_cnt++; // Output table name as comment if this is the first record of the table @@ -206,7 +206,7 @@ class ExportYaml extends ExportPlugin return false; } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return true; } // end getTableYAML diff --git a/libraries/plugins/export/PMA_ExportPdf.class.php b/libraries/plugins/export/PMA_ExportPdf.class.php index a8c88fa531..c3b48cf0ef 100644 --- a/libraries/plugins/export/PMA_ExportPdf.class.php +++ b/libraries/plugins/export/PMA_ExportPdf.class.php @@ -178,7 +178,7 @@ class PMA_ExportPdf extends PMA_PDF $tmpheight = array(); $maxpage = $this->page; - while ($data = PMA_DBI_fetchRow($this->results)) { + while ($data = $GLOBALS['dbi']->fetchRow($this->results)) { $this->page = $currpage; // write the horizontal borders $this->Line($l, $h, $fullwidth+$l, $h); @@ -277,9 +277,9 @@ class PMA_ExportPdf extends PMA_PDF /** * Pass 1 for column widths */ - $this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED); - $this->numFields = PMA_DBI_numFields($this->results); - $this->fields = PMA_DBI_getFieldsMeta($this->results); + $this->results = $GLOBALS['dbi']->query($query, null, PMA_DBI_QUERY_UNBUFFERED); + $this->numFields = $GLOBALS['dbi']->numFields($this->results); + $this->fields = $GLOBALS['dbi']->getFieldsMeta($this->results); // sColWidth = starting col width (an average size width) $availableWidth = $this->w - $this->lMargin - $this->rMargin; @@ -345,7 +345,7 @@ class PMA_ExportPdf extends PMA_PDF /** * @todo force here a LIMIT to avoid reading all rows */ - while ($row = PMA_DBI_fetchRow($this->results)) { + while ($row = $GLOBALS['dbi']->fetchRow($this->results)) { foreach ($colFits as $key => $val) { $stringWidth = $this->getstringwidth($row[$key]) + 6 ; if ($adjustingMode && ($stringWidth > $this->sColWidth)) { @@ -391,16 +391,16 @@ class PMA_ExportPdf extends PMA_PDF ksort($this->tablewidths); - PMA_DBI_freeResult($this->results); + $GLOBALS['dbi']->freeResult($this->results); // Pass 2 - $this->results = PMA_DBI_query($query, null, PMA_DBI_QUERY_UNBUFFERED); + $this->results = $GLOBALS['dbi']->query($query, null, PMA_DBI_QUERY_UNBUFFERED); $this->setY($this->tMargin); $this->AddPage(); $this->SetFont(PMA_PDF_FONT, '', 9); $this->morepagestable($this->FontSizePt); - PMA_DBI_freeResult($this->results); + $GLOBALS['dbi']->freeResult($this->results); } // end of mysqlReport function diff --git a/libraries/plugins/import/ImportCsv.class.php b/libraries/plugins/import/ImportCsv.class.php index 21d06932b2..952e792d90 100644 --- a/libraries/plugins/import/ImportCsv.class.php +++ b/libraries/plugins/import/ImportCsv.class.php @@ -186,7 +186,7 @@ class ImportCsv extends AbstractImportCsv } $sql_template .= ' INTO ' . PMA_Util::backquote($table); - $tmp_fields = PMA_DBI_getColumns($db, $table); + $tmp_fields = $GLOBALS['dbi']->getColumns($db, $table); if (empty($csv_columns)) { $fields = $tmp_fields; @@ -503,7 +503,7 @@ class ImportCsv extends AbstractImportCsv } if (strlen($db)) { - $result = PMA_DBI_fetchResult('SHOW TABLES'); + $result = $GLOBALS['dbi']->fetchResult('SHOW TABLES'); $tbl_name = 'TABLE '.(count($result) + 1); } else { $tbl_name = 'TBL_NAME'; diff --git a/libraries/plugins/import/ImportLdi.class.php b/libraries/plugins/import/ImportLdi.class.php index 20665078e5..dd3dc3da4d 100644 --- a/libraries/plugins/import/ImportLdi.class.php +++ b/libraries/plugins/import/ImportLdi.class.php @@ -46,14 +46,14 @@ class ImportLdi extends AbstractImportCsv if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') { $GLOBALS['cfg']['Import']['ldi_local_option'] = false; - $result = PMA_DBI_tryQuery('SHOW VARIABLES LIKE \'local\\_infile\';'); - if ($result != false && PMA_DBI_numRows($result) > 0) { - $tmp = PMA_DBI_fetchRow($result); + $result = $GLOBALS['dbi']->tryQuery('SHOW VARIABLES LIKE \'local\\_infile\';'); + if ($result != false && $GLOBALS['dbi']->numRows($result) > 0) { + $tmp = $GLOBALS['dbi']->fetchRow($result); if ($tmp[1] == 'ON') { $GLOBALS['cfg']['Import']['ldi_local_option'] = true; } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); unset($result); } diff --git a/libraries/plugins/import/ImportMediawiki.class.php b/libraries/plugins/import/ImportMediawiki.class.php index 096fbc8e09..48870f7018 100644 --- a/libraries/plugins/import/ImportMediawiki.class.php +++ b/libraries/plugins/import/ImportMediawiki.class.php @@ -358,7 +358,7 @@ class ImportMediawiki extends ImportPlugin private function _setTableName(&$table_name) { if (empty($table_name)) { - $result = PMA_DBI_fetchResult('SHOW TABLES'); + $result = $GLOBALS['dbi']->fetchResult('SHOW TABLES'); // todo check if the name below already exists $table_name = 'TABLE '.(count($result) + 1); } diff --git a/libraries/plugins/import/ImportShp.class.php b/libraries/plugins/import/ImportShp.class.php index decc515935..56721149f7 100644 --- a/libraries/plugins/import/ImportShp.class.php +++ b/libraries/plugins/import/ImportShp.class.php @@ -276,7 +276,7 @@ class ImportShp extends ImportPlugin // Set table name based on the number of tables if (strlen($db)) { - $result = PMA_DBI_fetchResult('SHOW TABLES'); + $result = $GLOBALS['dbi']->fetchResult('SHOW TABLES'); $table_name = 'TABLE '.(count($result) + 1); } else { $table_name = 'TBL_NAME'; diff --git a/libraries/plugins/import/ImportSql.class.php b/libraries/plugins/import/ImportSql.class.php index 871eb99607..d3520fa52a 100644 --- a/libraries/plugins/import/ImportSql.class.php +++ b/libraries/plugins/import/ImportSql.class.php @@ -49,7 +49,7 @@ class ImportSql extends ImportPlugin $importPluginProperties->setExtension('sql'); $importPluginProperties->setOptionsText(__('Options')); - $compats = PMA_DBI_getCompatibilities(); + $compats = $GLOBALS['dbi']->getCompatibilities(); if (count($compats) > 0) { $values = array(); foreach ($compats as $val) { @@ -152,7 +152,7 @@ class ImportSql extends ImportPlugin $sql_modes[] = 'NO_AUTO_VALUE_ON_ZERO'; } if (count($sql_modes) > 0) { - PMA_DBI_tryQuery('SET SQL_MODE="' . implode(',', $sql_modes) . '"'); + $GLOBALS['dbi']->tryQuery('SET SQL_MODE="' . implode(',', $sql_modes) . '"'); } unset($sql_modes); diff --git a/libraries/pmd_common.php b/libraries/pmd_common.php index 406f1f2bc0..aa912632dc 100644 --- a/libraries/pmd_common.php +++ b/libraries/pmd_common.php @@ -27,9 +27,9 @@ function get_tables_info() $GLOBALS['PMD']['OWNER'] = array(); $GLOBALS['PMD']['TABLE_NAME_SMALL'] = array(); - $tables = PMA_DBI_getTablesFull($GLOBALS['db']); + $tables = $GLOBALS['dbi']->getTablesFull($GLOBALS['db']); // seems to be needed later - PMA_DBI_selectDb($GLOBALS['db']); + $GLOBALS['dbi']->selectDb($GLOBALS['db']); $i = 0; foreach ($tables as $one_table) { $GLOBALS['PMD']['TABLE_NAME'][$i] @@ -73,11 +73,11 @@ function get_tables_info() */ function get_columns_info() { - PMA_DBI_selectDb($GLOBALS['db']); + $GLOBALS['dbi']->selectDb($GLOBALS['db']); $tab_column = array(); for ($i = 0, $cnt = count($GLOBALS['PMD']["TABLE_NAME"]); $i < $cnt; $i++) { - $fields_rs = PMA_DBI_query( - PMA_DBI_getColumnsSql( + $fields_rs = $GLOBALS['dbi']->query( + $GLOBALS['dbi']->getColumnsSql( $GLOBALS['db'], $GLOBALS['PMD']["TABLE_NAME_SMALL"][$i], null, @@ -88,7 +88,7 @@ function get_columns_info() ); $tbl_name_i = $GLOBALS['PMD']['TABLE_NAME'][$i]; $j = 0; - while ($row = PMA_DBI_fetchAssoc($fields_rs)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($fields_rs)) { $tab_column[$tbl_name_i]['COLUMN_ID'][$j] = $j; $tab_column[$tbl_name_i]['COLUMN_NAME'][$j] = $row['Field']; $tab_column[$tbl_name_i]['TYPE'][$j] = $row['Type']; @@ -106,15 +106,15 @@ function get_columns_info() */ function get_script_contr() { - PMA_DBI_selectDb($GLOBALS['db']); + $GLOBALS['dbi']->selectDb($GLOBALS['db']); $con["C_NAME"] = array(); $i = 0; - $alltab_rs = PMA_DBI_query( + $alltab_rs = $GLOBALS['dbi']->query( 'SHOW TABLES FROM ' . PMA_Util::backquote($GLOBALS['db']), null, PMA_DBI_QUERY_STORE ); - while ($val = @PMA_DBI_fetchRow($alltab_rs)) { + while ($val = @$GLOBALS['dbi']->fetchRow($alltab_rs)) { $row = PMA_getForeigners($GLOBALS['db'], $val[0], '', 'internal'); //echo "<br> internal ".$GLOBALS['db']." - ".$val[0]." - "; //print_r($row); @@ -254,7 +254,7 @@ function get_tab_pos() `h` AS `H` FROM " . PMA_Util::backquote($cfgRelation['db']) . "." . PMA_Util::backquote($cfgRelation['designer_coords']); - $tab_pos = PMA_DBI_fetchResult( + $tab_pos = $GLOBALS['dbi']->fetchResult( $query, 'name', null, $GLOBALS['controllink'], PMA_DBI_QUERY_STORE ); return count($tab_pos) ? $tab_pos : null; diff --git a/libraries/relation.lib.php b/libraries/relation.lib.php index 6da2f18e82..497b489912 100644 --- a/libraries/relation.lib.php +++ b/libraries/relation.lib.php @@ -30,14 +30,14 @@ function PMA_queryAsControlUser($sql, $show_error = true, $options = 0) $cache_affected_rows = false; if ($show_error) { - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( $sql, $GLOBALS['controllink'], $options, $cache_affected_rows ); } else { - $result = @PMA_DBI_tryQuery( + $result = @$GLOBALS['dbi']->tryQuery( $sql, $GLOBALS['controllink'], $options, @@ -365,7 +365,7 @@ function PMA_checkRelationsParam() if ($GLOBALS['server'] == 0 || empty($GLOBALS['cfg']['Server']['pmadb']) - || ! PMA_DBI_selectDb($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink']) + || ! $GLOBALS['dbi']->selectDb($GLOBALS['cfg']['Server']['pmadb'], $GLOBALS['controllink']) ) { // No server selected -> no bookmark table // we return the array with the falses in it, @@ -395,7 +395,7 @@ function PMA_checkRelationsParam() return $cfgRelation; } - while ($curr_table = @PMA_DBI_fetchRow($tab_rs)) { + while ($curr_table = @$GLOBALS['dbi']->fetchRow($tab_rs)) { if ($curr_table[0] == $GLOBALS['cfg']['Server']['bookmarktable']) { $cfgRelation['bookmark'] = $curr_table[0]; } elseif ($curr_table[0] == $GLOBALS['cfg']['Server']['relation']) { @@ -422,7 +422,7 @@ function PMA_checkRelationsParam() $cfgRelation['userconfig'] = $curr_table[0]; } } // end while - PMA_DBI_freeResult($tab_rs); + $GLOBALS['dbi']->freeResult($tab_rs); if (isset($cfgRelation['relation'])) { $cfgRelation['relwork'] = true; @@ -515,7 +515,7 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') $rel_query .= ' AND `master_field` = ' . '\'' . PMA_Util::sqlAddSlashes($column) . '\''; } - $foreign = PMA_DBI_fetchResult( + $foreign = $GLOBALS['dbi']->fetchResult( $rel_query, 'master_field', null, $GLOBALS['controllink'] ); } @@ -524,7 +524,7 @@ function PMA_getForeigners($db, $table, $column = '', $source = 'both') $show_create_table_query = 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table); - $show_create_table = PMA_DBI_fetchValue($show_create_table_query, 0, 1); + $show_create_table = $GLOBALS['dbi']->fetchValue($show_create_table_query, 0, 1); $analyzed_sql = PMA_SQP_analyze(PMA_SQP_parse($show_create_table)); foreach ($analyzed_sql[0]['foreign_keys'] as $one_key) { @@ -621,7 +621,7 @@ function PMA_getDisplayField($db, $table) WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($db) . '\' AND `table_name` = \'' . PMA_Util::sqlAddSlashes($table) . '\''; - $row = PMA_DBI_fetchSingleRow( + $row = $GLOBALS['dbi']->fetchSingleRow( $disp_query, 'ASSOC', $GLOBALS['controllink'] ); if (isset($row['display_field'])) { @@ -664,7 +664,7 @@ function PMA_getComments($db, $table = '') if ($table != '') { // MySQL native column comments - $columns = PMA_DBI_getColumns($db, $table, null, true); + $columns = $GLOBALS['dbi']->getColumns($db, $table, null, true); if ($columns) { foreach ($columns as $column) { if (! empty($column['Comment'])) { @@ -704,11 +704,11 @@ function PMA_getDbComment($db) AND column_name = '(db_comment)'"; $com_rs = PMA_queryAsControlUser($com_qry, true, PMA_DBI_QUERY_STORE); - if ($com_rs && PMA_DBI_numRows($com_rs) > 0) { - $row = PMA_DBI_fetchAssoc($com_rs); + if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { + $row = $GLOBALS['dbi']->fetchAssoc($com_rs); $comment = $row['comment']; } - PMA_DBI_freeResult($com_rs); + $GLOBALS['dbi']->freeResult($com_rs); } return $comment; @@ -735,12 +735,12 @@ function PMA_getDbComments() WHERE `column_name` = '(db_comment)'"; $com_rs = PMA_queryAsControlUser($com_qry, true, PMA_DBI_QUERY_STORE); - if ($com_rs && PMA_DBI_numRows($com_rs) > 0) { - while ($row = PMA_DBI_fetchAssoc($com_rs)) { + if ($com_rs && $GLOBALS['dbi']->numRows($com_rs) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($com_rs)) { $comments[$row['db_name']] = $row['comment']; } } - PMA_DBI_freeResult($com_rs); + $GLOBALS['dbi']->freeResult($com_rs); } return $comments; @@ -884,7 +884,7 @@ function PMA_getHistory($username) WHERE `username` = \'' . PMA_Util::sqlAddSlashes($username) . '\' ORDER BY `id` DESC'; - return PMA_DBI_fetchResult($hist_query, null, null, $GLOBALS['controllink']); + return $GLOBALS['dbi']->fetchResult($hist_query, null, null, $GLOBALS['controllink']); } // end of 'PMA_getHistory()' function /** @@ -918,7 +918,7 @@ function PMA_purgeHistory($username) ORDER BY `timevalue` DESC LIMIT ' . $GLOBALS['cfg']['QueryHistoryMax'] . ', 1'; - if ($max_time = PMA_DBI_fetchValue($search_query, 0, 0, $GLOBALS['controllink'])) { + if ($max_time = $GLOBALS['dbi']->fetchValue($search_query, 0, 0, $GLOBALS['controllink'])) { PMA_queryAsControlUser( 'DELETE FROM ' . PMA_Util::backquote($cfgRelation['db']) . '.' @@ -1136,31 +1136,31 @@ function PMA_getForeignData( $f_query_limit = isset($foreign_limit) ? $foreign_limit : ''; if (!empty($foreign_filter)) { - $res = PMA_DBI_query( + $res = $GLOBALS['dbi']->query( 'SELECT COUNT(*)' . $f_query_from . $f_query_filter ); if ($res) { - $the_total = PMA_DBI_fetchValue($res); - @PMA_DBI_freeResult($res); + $the_total = $GLOBALS['dbi']->fetchValue($res); + @$GLOBALS['dbi']->freeResult($res); } else { $the_total = 0; } } - $disp = PMA_DBI_query( + $disp = $GLOBALS['dbi']->query( $f_query_main . $f_query_from . $f_query_filter . $f_query_order . $f_query_limit ); - if ($disp && PMA_DBI_numRows($disp) > 0) { + if ($disp && $GLOBALS['dbi']->numRows($disp) > 0) { // If a resultset has been created, pre-cache it in the $disp_row // array. This helps us from not needing to use mysql_data_seek by // accessing a pre-cached PHP array. Usually those resultsets are // not that big, so a performance hit should not be expected. $disp_row = array(); - while ($single_disp_row = @PMA_DBI_fetchAssoc($disp)) { + while ($single_disp_row = @$GLOBALS['dbi']->fetchAssoc($disp)) { $disp_row[] = $single_disp_row; } - @PMA_DBI_freeResult($disp); + @$GLOBALS['dbi']->freeResult($disp); } } else { $disp_row = null; @@ -1216,8 +1216,8 @@ function PMA_getRelatives($all_tables, $master) . ' AND ' . $to . '_db = \'' . PMA_Util::sqlAddSlashes($GLOBALS['db']) . '\'' . ' AND ' . $from . '_table IN ' . $in_know . ' AND ' . $to . '_table IN ' . $in_left; - $relations = @PMA_DBI_query($rel_query, $GLOBALS['controllink']); - while ($row = PMA_DBI_fetchAssoc($relations)) { + $relations = @$GLOBALS['dbi']->query($rel_query, $GLOBALS['controllink']); + while ($row = $GLOBALS['dbi']->fetchAssoc($relations)) { $found_table = $row[$to . '_table']; if (isset($remaining_tables[$found_table])) { $fromclause @@ -1426,7 +1426,7 @@ function PMA_REL_createPage($newpage, $cfgRelation, $db) . PMA_Util::sqlAddSlashes($newpage) . '\')'; PMA_queryAsControlUser($ins_query, false); - return PMA_DBI_insertId( + return $GLOBALS['dbi']->insertId( isset($GLOBALS['controllink']) ? $GLOBALS['controllink'] : '' ); } diff --git a/libraries/replication.inc.php b/libraries/replication.inc.php index da499513ba..e017f58b14 100644 --- a/libraries/replication.inc.php +++ b/libraries/replication.inc.php @@ -13,12 +13,12 @@ if (! defined('PHPMYADMIN')) { /** * get master replication from server */ -$server_master_replication = PMA_DBI_fetchResult('SHOW MASTER STATUS'); +$server_master_replication = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS'); /** * get slave replication from server */ -$server_slave_replication = PMA_DBI_fetchResult('SHOW SLAVE STATUS'); +$server_slave_replication = $GLOBALS['dbi']->fetchResult('SHOW SLAVE STATUS'); /** * replication types @@ -199,7 +199,7 @@ function PMA_Replication_Slave_control($action, $control = null, $link = null) return -1; } - return PMA_DBI_tryQuery($action . " SLAVE " . $control . ";", $link); + return $GLOBALS['dbi']->tryQuery($action . " SLAVE " . $control . ";", $link); } /** @@ -224,7 +224,7 @@ function PMA_Replication_Slave_changeMaster($user, $password, $host, $port, PMA_Replication_Slave_control("STOP", null, $link); } - $out = PMA_DBI_tryQuery( + $out = $GLOBALS['dbi']->tryQuery( 'CHANGE MASTER TO ' . 'MASTER_HOST=\'' . $host . '\',' . 'MASTER_PORT=' . ($port * 1) . ',' . @@ -262,7 +262,7 @@ function PMA_Replication_connectToMaster( // 5th parameter set to true means that it's an auxiliary connection // and we must not go back to login page if it fails - return PMA_DBI_connect($user, $password, false, $server, true); + return $GLOBALS['dbi']->connect($user, $password, false, $server, true); } /** * Fetches position and file of current binary log on master @@ -274,7 +274,7 @@ function PMA_Replication_connectToMaster( */ function PMA_Replication_Slave_binLogMaster($link = null) { - $data = PMA_DBI_fetchResult('SHOW MASTER STATUS', null, null, $link); + $data = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS', null, null, $link); $output = array(); if (! empty($data)) { @@ -295,7 +295,7 @@ function PMA_Replication_Slave_binLogMaster($link = null) function PMA_Replication_Master_getReplicatedDbs($link = null) { // let's find out, which databases are replicated - $data = PMA_DBI_fetchResult('SHOW MASTER STATUS', null, null, $link); + $data = $GLOBALS['dbi']->fetchResult('SHOW MASTER STATUS', null, null, $link); $do_db = array(); $ignore_db = array(); @@ -307,9 +307,9 @@ function PMA_Replication_Master_getReplicatedDbs($link = null) $ignore_db = explode(',', $data[0]['Binlog_Ignore_DB']); } - $tmp_alldbs = PMA_DBI_query('SHOW DATABASES;', $link); - while ($tmp_row = PMA_DBI_fetchRow($tmp_alldbs)) { - if (PMA_isSystemSchema($tmp_row[0])) { + $tmp_alldbs = $GLOBALS['dbi']->query('SHOW DATABASES;', $link); + while ($tmp_row = $GLOBALS['dbi']->fetchRow($tmp_alldbs)) { + if ($GLOBALS['dbi']->isSystemSchema($tmp_row[0])) { continue; } if (count($do_db) == 0) { diff --git a/libraries/replication_gui.lib.php b/libraries/replication_gui.lib.php index ead99533e9..720751ebdc 100644 --- a/libraries/replication_gui.lib.php +++ b/libraries/replication_gui.lib.php @@ -19,7 +19,7 @@ function PMA_replication_db_multibox() $multi_values .= '<select name="db_select[]" size="6" multiple="multiple" id="db_select">'; foreach ($GLOBALS['pma']->databases as $current_db) { - if (PMA_isSystemSchema($current_db)) { + if ($GLOBALS['dbi']->isSystemSchema($current_db)) { continue; } if (! empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) { @@ -103,7 +103,7 @@ function PMA_replication_print_status_table($type, $hidden = false, $title = tru // [ERROR] Error reading packet from server: Misconfigured master - server id was not set ( server_errno=1236) // [ERROR] Got fatal error 1236: 'Misconfigured master - server id was not set' from master when reading data from binary log // - //$server_id = PMA_DBI_fetchValue("SHOW VARIABLES LIKE 'server_id'", 0, 1); + //$server_id = $GLOBALS['dbi']->fetchValue("SHOW VARIABLES LIKE 'server_id'", 0, 1); echo '<div id="replication_' . $type . '_section" style="' . ($hidden ? 'display: none;' : '') . '"> '; @@ -184,7 +184,7 @@ function PMA_replication_print_slaves_table($hidden = false) { // Fetch data - $data = PMA_DBI_fetchResult('SHOW SLAVE HOSTS', null, null); + $data = $GLOBALS['dbi']->fetchResult('SHOW SLAVE HOSTS', null, null); echo ' <br />'; echo ' <div id="replication_slaves_section" style="' . ($hidden ? 'display: none;' : '') . '"> '; @@ -223,7 +223,7 @@ function PMA_replication_print_slaves_table($hidden = false) function PMA_replication_get_username_hostname_length() { - $fields_info = PMA_DBI_getColumns('mysql', 'user'); + $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user'); $username_length = 16; $hostname_length = 41; foreach ($fields_info as $val) { @@ -294,7 +294,7 @@ function PMA_replication_gui_master_addslaveuser() . '</label>' . '<span class="options">' . ' <select name="pred_hostname" id="select_pred_hostname" title="' . __('Host') . '"'; - $_current_user = PMA_DBI_fetchValue('SELECT USER();'); + $_current_user = $GLOBALS['dbi']->fetchValue('SELECT USER();'); if (! empty($_current_user)) { $thishost = str_replace("'", '', substr($_current_user, (strrpos($_current_user, '@') + 1))); if ($thishost == 'localhost' || $thishost == '127.0.0.1') { diff --git a/libraries/rte/rte_events.lib.php b/libraries/rte/rte_events.lib.php index eb6b47e3e8..74c6b7a0f5 100644 --- a/libraries/rte/rte_events.lib.php +++ b/libraries/rte/rte_events.lib.php @@ -67,7 +67,7 @@ function PMA_EVN_main() $where = "EVENT_SCHEMA='" . PMA_Util::sqlAddSlashes($db) . "'"; $query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` " . "WHERE $where ORDER BY `EVENT_NAME` ASC;"; - $items = PMA_DBI_fetchResult($query); + $items = $GLOBALS['dbi']->fetchResult($query); echo PMA_RTE_getList('event', $items); /** * Display a link for adding a new event, if @@ -97,33 +97,33 @@ function PMA_EVN_handleEditor() // Execute the created query if (! empty($_REQUEST['editor_process_edit'])) { // Backup the old trigger, in case something goes wrong - $create_item = PMA_DBI_getDefinition( + $create_item = $GLOBALS['dbi']->getDefinition( $db, 'EVENT', $_REQUEST['item_original_name'] ); $drop_item = "DROP EVENT " . PMA_Util::backquote($_REQUEST['item_original_name']) . ";\n"; - $result = PMA_DBI_tryQuery($drop_item); + $result = $GLOBALS['dbi']->tryQuery($drop_item); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($drop_item) ) . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { - $result = PMA_DBI_tryQuery($item_query); + $result = $GLOBALS['dbi']->tryQuery($item_query); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($item_query) ) . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); // We dropped the old item, but were unable to create // the new one. Try to restore the backup query - $result = PMA_DBI_tryQuery($create_item); + $result = $GLOBALS['dbi']->tryQuery($create_item); if (! $result) { // OMG, this is really bad! We dropped the query, // failed to create a new one @@ -137,7 +137,7 @@ function PMA_EVN_handleEditor() . __('The backed up query was:') . "\"" . htmlspecialchars($create_item) . "\"" . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } } else { $message = PMA_Message::success( @@ -151,14 +151,14 @@ function PMA_EVN_handleEditor() } } else { // 'Add a new item' mode - $result = PMA_DBI_tryQuery($item_query); + $result = $GLOBALS['dbi']->tryQuery($item_query); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($item_query) ) . '<br /><br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $message = PMA_Message::success( __('Event %1$s has been created.') @@ -190,7 +190,7 @@ function PMA_EVN_handleEditor() . PMA_Util::sqlAddSlashes($_REQUEST['item_name']) . "'"; $query = "SELECT " . $columns . " FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE " . $where. ";"; - $event = PMA_DBI_fetchSingleRow($query); + $event = $GLOBALS['dbi']->fetchSingleRow($query); $response->addJSON( 'name', htmlspecialchars(strtoupper($_REQUEST['item_name'])) @@ -322,7 +322,7 @@ function PMA_EVN_getDataFromName($name) $where = "EVENT_SCHEMA='" . PMA_Util::sqlAddSlashes($db) . "' " . "AND EVENT_NAME='" . PMA_Util::sqlAddSlashes($name) . "'"; $query = "SELECT $columns FROM `INFORMATION_SCHEMA`.`EVENTS` WHERE $where;"; - $item = PMA_DBI_fetchSingleRow($query); + $item = $GLOBALS['dbi']->fetchSingleRow($query); if (! $item) { return false; } diff --git a/libraries/rte/rte_export.lib.php b/libraries/rte/rte_export.lib.php index 28b8798299..8fd9a7c4d7 100644 --- a/libraries/rte/rte_export.lib.php +++ b/libraries/rte/rte_export.lib.php @@ -66,7 +66,7 @@ function PMA_EVN_handleExport() if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) { $item_name = $_GET['item_name']; - $export_data = PMA_DBI_getDefinition($db, 'EVENT', $item_name); + $export_data = $GLOBALS['dbi']->getDefinition($db, 'EVENT', $item_name); PMA_RTE_handleExport($item_name, $export_data); } } // end PMA_EVN_handleExport() @@ -86,7 +86,7 @@ function PMA_RTN_handleExport() && ! empty($_GET['item_type']) ) { if ($_GET['item_type'] == 'FUNCTION' || $_GET['item_type'] == 'PROCEDURE') { - $export_data = PMA_DBI_getDefinition( + $export_data = $GLOBALS['dbi']->getDefinition( $db, $_GET['item_type'], $_GET['item_name'] @@ -108,7 +108,7 @@ function PMA_TRI_handleExport() if (! empty($_GET['export_item']) && ! empty($_GET['item_name'])) { $item_name = $_GET['item_name']; - $triggers = PMA_DBI_getTriggers($db, $table, ''); + $triggers = $GLOBALS['dbi']->getTriggers($db, $table, ''); $export_data = false; foreach ($triggers as $trigger) { if ($trigger['name'] === $item_name) { diff --git a/libraries/rte/rte_footer.lib.php b/libraries/rte/rte_footer.lib.php index 0ea4e72f81..8d69812ab0 100644 --- a/libraries/rte/rte_footer.lib.php +++ b/libraries/rte/rte_footer.lib.php @@ -80,7 +80,7 @@ function PMA_EVN_getFooterLinks() * a form for toggling the state of the event scheduler */ // Init options for the event scheduler toggle functionality - $es_state = PMA_DBI_fetchValue( + $es_state = $GLOBALS['dbi']->fetchValue( "SHOW GLOBAL VARIABLES LIKE 'event_scheduler'", 0, 1 diff --git a/libraries/rte/rte_main.inc.php b/libraries/rte/rte_main.inc.php index 6e394f1b61..a36221c9c5 100644 --- a/libraries/rte/rte_main.inc.php +++ b/libraries/rte/rte_main.inc.php @@ -22,7 +22,7 @@ if ($GLOBALS['is_ajax_request'] != true) { /** * Displays the header and tabs */ - if (! empty($table) && in_array($table, PMA_DBI_getTables($db))) { + if (! empty($table) && in_array($table, $GLOBALS['dbi']->getTables($db))) { include_once './libraries/tbl_common.inc.php'; } else { $table = ''; @@ -36,7 +36,7 @@ if ($GLOBALS['is_ajax_request'] != true) { * create the missing $url_query variable */ if (strlen($db)) { - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); if (! isset($url_query)) { $url_query = PMA_generate_common_url($db, $table); } diff --git a/libraries/rte/rte_routines.lib.php b/libraries/rte/rte_routines.lib.php index e6550f5301..e4e2a707e8 100644 --- a/libraries/rte/rte_routines.lib.php +++ b/libraries/rte/rte_routines.lib.php @@ -52,7 +52,7 @@ function PMA_RTN_main() $columns = "`SPECIFIC_NAME`, `ROUTINE_NAME`, `ROUTINE_TYPE`, "; $columns .= "`DTD_IDENTIFIER`, `ROUTINE_DEFINITION`"; $where = "ROUTINE_SCHEMA='" . PMA_Util::sqlAddSlashes($db) . "'"; - $items = PMA_DBI_fetchResult( + $items = $GLOBALS['dbi']->fetchResult( "SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES` WHERE $where;" ); echo PMA_RTE_getList('routine', $items); @@ -283,34 +283,34 @@ function PMA_RTN_handleEditor() ); } else { // Backup the old routine, in case something goes wrong - $create_routine = PMA_DBI_getDefinition( + $create_routine = $GLOBALS['dbi']->getDefinition( $db, $_REQUEST['item_original_type'], $_REQUEST['item_original_name'] ); $drop_routine = "DROP {$_REQUEST['item_original_type']} " . PMA_Util::backquote($_REQUEST['item_original_name']) . ";\n"; - $result = PMA_DBI_tryQuery($drop_routine); + $result = $GLOBALS['dbi']->tryQuery($drop_routine); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($drop_routine) ) . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { - $result = PMA_DBI_tryQuery($routine_query); + $result = $GLOBALS['dbi']->tryQuery($routine_query); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($routine_query) ) . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); // We dropped the old routine, // but were unable to create the new one // Try to restore the backup query - $result = PMA_DBI_tryQuery($create_routine); + $result = $GLOBALS['dbi']->tryQuery($create_routine); if (! $result) { // OMG, this is really bad! We dropped the query, // failed to create a new one @@ -325,7 +325,7 @@ function PMA_RTN_handleEditor() . __('The backed up query was:') . "\"" . htmlspecialchars($create_routine) . "\"" . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } } else { $message = PMA_Message::success( @@ -340,14 +340,14 @@ function PMA_RTN_handleEditor() } } else { // 'Add a new routine' mode - $result = PMA_DBI_tryQuery($routine_query); + $result = $GLOBALS['dbi']->tryQuery($routine_query); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($routine_query) ) . '<br /><br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $message = PMA_Message::success( __('Routine %1$s has been created.') @@ -385,7 +385,7 @@ function PMA_RTN_handleEditor() . PMA_Util::sqlAddSlashes($_REQUEST['item_name']) . "'" . "AND ROUTINE_TYPE='" . PMA_Util::sqlAddSlashes($_REQUEST['item_type']) . "'"; - $routine = PMA_DBI_fetchSingleRow( + $routine = $GLOBALS['dbi']->fetchSingleRow( "SELECT $columns FROM `INFORMATION_SCHEMA`.`ROUTINES`" . " WHERE $where;" ); @@ -618,7 +618,7 @@ function PMA_RTN_getDataFromName($name, $type, $all = true) . "AND ROUTINE_TYPE='" . PMA_Util::sqlAddSlashes($type) . "'"; $query = "SELECT $fields FROM INFORMATION_SCHEMA.ROUTINES WHERE $where;"; - $routine = PMA_DBI_fetchSingleRow($query); + $routine = $GLOBALS['dbi']->fetchSingleRow($query); if (! $routine) { return false; @@ -628,7 +628,7 @@ function PMA_RTN_getDataFromName($name, $type, $all = true) $retval['item_name'] = $routine['SPECIFIC_NAME']; $retval['item_type'] = $routine['ROUTINE_TYPE']; $parsed_query = PMA_SQP_parse( - PMA_DBI_getDefinition( + $GLOBALS['dbi']->getDefinition( $db, $routine['ROUTINE_TYPE'], $routine['SPECIFIC_NAME'] @@ -1349,7 +1349,7 @@ function PMA_RTN_handleExecute() $affected = 0; // Execute query - if (! PMA_DBI_tryMultiQuery($multiple_query)) { + if (! $GLOBALS['dbi']->tryMultiQuery($multiple_query)) { $outcome = false; } @@ -1373,13 +1373,13 @@ function PMA_RTN_handleExecute() do { - $result = PMA_DBI_storeResult(); - $num_rows = PMA_DBI_numRows($result); + $result = $GLOBALS['dbi']->storeResult(); + $num_rows = $GLOBALS['dbi']->numRows($result); if (($result !== false) && ($num_rows > 0)) { $output .= "<table><tr>"; - foreach (PMA_DBI_getFieldsMeta($result) as $key => $field) { + foreach ($GLOBALS['dbi']->getFieldsMeta($result) as $key => $field) { $output .= "<th>"; $output .= htmlspecialchars($field->name); $output .= "</th>"; @@ -1388,7 +1388,7 @@ function PMA_RTN_handleExecute() $color_class = 'odd'; - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { $output .= "<tr>"; foreach ($row as $key => $value) { if ($value === null) { @@ -1409,15 +1409,15 @@ function PMA_RTN_handleExecute() } - if (! PMA_DBI_moreResults()) { + if (! $GLOBALS['dbi']->moreResults()) { break; } $output .= "<br/>"; - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); - } while (PMA_DBI_nextResult()); + } while ($GLOBALS['dbi']->nextResult()); $output .= "</fieldset>"; @@ -1453,7 +1453,7 @@ function PMA_RTN_handleExecute() htmlspecialchars($multiple_query) ) . '<br /><br />' - . __('MySQL said: ') . PMA_DBI_getError(null) + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null) ); } diff --git a/libraries/rte/rte_triggers.lib.php b/libraries/rte/rte_triggers.lib.php index f838c3eeec..eb8a5ab8a4 100644 --- a/libraries/rte/rte_triggers.lib.php +++ b/libraries/rte/rte_triggers.lib.php @@ -44,7 +44,7 @@ function PMA_TRI_main() /** * Display a list of available triggers */ - $items = PMA_DBI_getTriggers($db, $table); + $items = $GLOBALS['dbi']->getTriggers($db, $table); echo PMA_RTE_getList('trigger', $items); /** * Display a link for adding a new trigger, @@ -76,26 +76,26 @@ function PMA_TRI_handleEditor() $trigger = PMA_TRI_getDataFromName($_REQUEST['item_original_name']); $create_item = $trigger['create']; $drop_item = $trigger['drop'] . ';'; - $result = PMA_DBI_tryQuery($drop_item); + $result = $GLOBALS['dbi']->tryQuery($drop_item); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($drop_item) ) . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { - $result = PMA_DBI_tryQuery($item_query); + $result = $GLOBALS['dbi']->tryQuery($item_query); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($item_query) ) . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); // We dropped the old item, but were unable to create the // new one. Try to restore the backup query. - $result = PMA_DBI_tryQuery($create_item); + $result = $GLOBALS['dbi']->tryQuery($create_item); if (! $result) { // OMG, this is really bad! We dropped the query, // failed to create a new one @@ -109,7 +109,7 @@ function PMA_TRI_handleEditor() . __('The backed up query was:') . "\"" . htmlspecialchars($create_item) . "\"" . '<br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } } else { $message = PMA_Message::success( @@ -123,14 +123,14 @@ function PMA_TRI_handleEditor() } } else { // 'Add a new item' mode - $result = PMA_DBI_tryQuery($item_query); + $result = $GLOBALS['dbi']->tryQuery($item_query); if (! $result) { $errors[] = sprintf( __('The following query has failed: "%s"'), htmlspecialchars($item_query) ) . '<br /><br />' - . __('MySQL said: ') . PMA_DBI_getError(null); + . __('MySQL said: ') . $GLOBALS['dbi']->getError(null); } else { $message = PMA_Message::success( __('Trigger %1$s has been created.') @@ -156,7 +156,7 @@ function PMA_TRI_handleEditor() if ($GLOBALS['is_ajax_request']) { $response = PMA_Response::getInstance(); if ($message->isSuccess()) { - $items = PMA_DBI_getTriggers($db, $table, ''); + $items = $GLOBALS['dbi']->getTriggers($db, $table, ''); $trigger = false; foreach ($items as $value) { if ($value['name'] == $_REQUEST['item_name']) { @@ -280,7 +280,7 @@ function PMA_TRI_getDataFromName($name) global $db, $table, $_REQUEST; $temp = array(); - $items = PMA_DBI_getTriggers($db, $table, ''); + $items = $GLOBALS['dbi']->getTriggers($db, $table, ''); foreach ($items as $value) { if ($value['name'] == $name) { $temp = $value; @@ -334,7 +334,7 @@ function PMA_TRI_getEditorForm($mode, $item) $query = "SELECT `TABLE_NAME` FROM `INFORMATION_SCHEMA`.`TABLES` "; $query .= "WHERE `TABLE_SCHEMA`='" . PMA_Util::sqlAddSlashes($db) . "' "; $query .= "AND `TABLE_TYPE`='BASE TABLE'"; - $tables = PMA_DBI_fetchResult($query); + $tables = $GLOBALS['dbi']->fetchResult($query); // Create the output $retval = ""; @@ -467,7 +467,7 @@ function PMA_TRI_getQueryFromRequest() } $query .= 'ON '; if (! empty($_REQUEST['item_table']) - && in_array($_REQUEST['item_table'], PMA_DBI_getTables($db)) + && in_array($_REQUEST['item_table'], $GLOBALS['dbi']->getTables($db)) ) { $query .= PMA_Util::backquote($_REQUEST['item_table']); } else { diff --git a/libraries/schema/Dia_Relation_Schema.class.php b/libraries/schema/Dia_Relation_Schema.class.php index ed8bc37389..c033cc0ad0 100644 --- a/libraries/schema/Dia_Relation_Schema.class.php +++ b/libraries/schema/Dia_Relation_Schema.class.php @@ -229,8 +229,8 @@ class Table_Stats $this->tableName = $tableName; $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName); - $result = PMA_DBI_tryQuery($sql, null, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + $result = $GLOBALS['dbi']->tryQuery($sql, null, PMA_DBI_QUERY_STORE); + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $dia->dieSchema( $pageNumber, "DIA", sprintf(__('The %s table doesn\'t exist!'), $tableName) @@ -251,7 +251,7 @@ class Table_Stats } $this->fields = array_keys($all_columns); } else { - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $this->fields[] = $row[0]; } } @@ -264,7 +264,7 @@ class Table_Stats . PMA_Util::sqlAddSlashes($tableName) . '\'' . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_queryAsControlUser($sql, false, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $dia->dieSchema( $pageNumber, "DIA", @@ -274,7 +274,7 @@ class Table_Stats ) ); } - list($this->x, $this->y) = PMA_DBI_fetchRow($result); + list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result); $this->x = (double) $this->x; $this->y = (double) $this->y; /* @@ -284,13 +284,13 @@ class Table_Stats /* * index */ - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE ); - if (PMA_DBI_numRows($result) > 0) { - while ($row = PMA_DBI_fetchAssoc($result)) { + if ($GLOBALS['dbi']->numRows($result) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } diff --git a/libraries/schema/Eps_Relation_Schema.class.php b/libraries/schema/Eps_Relation_Schema.class.php index 9034739437..dc7ba4ab51 100644 --- a/libraries/schema/Eps_Relation_Schema.class.php +++ b/libraries/schema/Eps_Relation_Schema.class.php @@ -418,8 +418,8 @@ class Table_Stats $this->_tableName = $tableName; $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName); - $result = PMA_DBI_tryQuery($sql, null, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + $result = $GLOBALS['dbi']->tryQuery($sql, null, PMA_DBI_QUERY_STORE); + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $eps->dieSchema( $pageNumber, "EPS", sprintf(__('The %s table doesn\'t exist!'), $tableName) @@ -441,7 +441,7 @@ class Table_Stats } $this->fields = array_keys($all_columns); } else { - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $this->fields[] = $row[0]; } } @@ -467,7 +467,7 @@ class Table_Stats . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_queryAsControlUser($sql, false, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $eps->dieSchema( $pageNumber, "EPS", sprintf( @@ -476,18 +476,18 @@ class Table_Stats ) ); } - list($this->x, $this->y) = PMA_DBI_fetchRow($result); + list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result); $this->x = (double) $this->x; $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $tableName); // index - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE ); - if (PMA_DBI_numRows($result) > 0) { - while ($row = PMA_DBI_fetchAssoc($result)) { + if ($GLOBALS['dbi']->numRows($result) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } diff --git a/libraries/schema/Export_Relation_Schema.class.php b/libraries/schema/Export_Relation_Schema.class.php index c075a92555..f40506ac44 100644 --- a/libraries/schema/Export_Relation_Schema.class.php +++ b/libraries/schema/Export_Relation_Schema.class.php @@ -200,10 +200,10 @@ class PMA_Export_Relation_Schema . ' AND pdf_page_number = ' . $pageNumber; $tab_rs = PMA_queryAsControlUser($tab_sql, null, PMA_DBI_QUERY_STORE); - if (! $tab_rs || ! PMA_DBI_numRows($tab_rs) > 0) { + if (! $tab_rs || ! $GLOBALS['dbi']->numRows($tab_rs) > 0) { $this->dieSchema('', __('This page does not contain any tables!')); } - while ($curr_table = @PMA_DBI_fetchAssoc($tab_rs)) { + while ($curr_table = @$GLOBALS['dbi']->fetchAssoc($tab_rs)) { $alltables[] = PMA_Util::sqlAddSlashes($curr_table['table_name']); } return $alltables; diff --git a/libraries/schema/Pdf_Relation_Schema.class.php b/libraries/schema/Pdf_Relation_Schema.class.php index 52bdafd7d9..36e3272bdc 100644 --- a/libraries/schema/Pdf_Relation_Schema.class.php +++ b/libraries/schema/Pdf_Relation_Schema.class.php @@ -215,7 +215,7 @@ class PMA_Schema_PDF extends PMA_PDF . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'' . ' AND page_nr = \'' . $pdf_page_number . '\''; $test_rs = PMA_queryAsControlUser($test_query); - $pages = @PMA_DBI_fetchAssoc($test_rs); + $pages = @$GLOBALS['dbi']->fetchAssoc($test_rs); $this->SetFont($this->_ff, 'B', 14); $this->Cell(0, 6, ucfirst($pages['page_descr']), 'B', 1, 'C'); $this->SetFont($this->_ff, ''); @@ -405,8 +405,8 @@ class Table_Stats $this->_tableName = $tableName; $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName); - $result = PMA_DBI_tryQuery($sql, null, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + $result = $GLOBALS['dbi']->tryQuery($sql, null, PMA_DBI_QUERY_STORE); + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $pdf->Error(sprintf(__('The %s table doesn\'t exist!'), $tableName)); } // load fields @@ -422,7 +422,7 @@ class Table_Stats } $this->fields = array_keys($all_columns); } else { - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $this->fields[] = $row[0]; } } @@ -444,7 +444,7 @@ class Table_Stats . ' AND table_name = \'' . PMA_Util::sqlAddSlashes($tableName) . '\'' . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_queryAsControlUser($sql, false, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $pdf->Error( sprintf( __('Please configure the coordinates for table %s'), @@ -452,7 +452,7 @@ class Table_Stats ) ); } - list($this->x, $this->y) = PMA_DBI_fetchRow($result); + list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result); $this->x = (double) $this->x; $this->y = (double) $this->y; /* @@ -462,12 +462,12 @@ class Table_Stats /* * index */ - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE ); - if (PMA_DBI_numRows($result) > 0) { - while ($row = PMA_DBI_fetchAssoc($result)) { + if ($GLOBALS['dbi']->numRows($result) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } @@ -1151,7 +1151,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema . ' WHERE page_nr = ' . $pageNumber; $_name_rs = PMA_queryAsControlUser($_name_sql); if ($_name_rs) { - $_name_row = PMA_DBI_fetchRow($_name_rs); + $_name_row = $GLOBALS['dbi']->fetchRow($_name_rs); $filename = $_name_row[0] . '.pdf'; } if (empty($filename)) { @@ -1189,7 +1189,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema 'L', 0, $pdf->PMA_links['doc'][$table]['-'] ); // $pdf->Ln(1); - $fields = PMA_DBI_getColumns($GLOBALS['db'], $table); + $fields = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $table); foreach ($fields as $row) { $pdf->SetX(20); $field_name = $row['Field']; @@ -1261,7 +1261,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema /** * Gets table keys and retains them */ - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW KEYS FROM ' . PMA_Util::backquote($table) . ';' ); $primary = ''; @@ -1271,7 +1271,7 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema $indexes_data = array(); $pk_array = array(); // will be use to emphasis prim. keys in the table // view - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { // Backups the list of primary keys if ($row['Key_name'] == 'PRIMARY') { $primary .= $row['Column_name'] . ', '; @@ -1301,13 +1301,13 @@ class PMA_Pdf_Relation_Schema extends PMA_Export_Relation_Schema } } // end while if ($result) { - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } /** * Gets fields properties */ - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); // Check if we can use Relations if (!empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in diff --git a/libraries/schema/Svg_Relation_Schema.class.php b/libraries/schema/Svg_Relation_Schema.class.php index d19f06f22a..7984543ee1 100644 --- a/libraries/schema/Svg_Relation_Schema.class.php +++ b/libraries/schema/Svg_Relation_Schema.class.php @@ -384,8 +384,8 @@ class Table_Stats $this->_tableName = $tableName; $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName); - $result = PMA_DBI_tryQuery($sql, null, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + $result = $GLOBALS['dbi']->tryQuery($sql, null, PMA_DBI_QUERY_STORE); + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $svg->dieSchema( $pageNumber, "SVG", @@ -409,7 +409,7 @@ class Table_Stats } $this->fields = array_keys($all_columns); } else { - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $this->fields[] = $row[0]; } } @@ -435,7 +435,7 @@ class Table_Stats . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_queryAsControlUser($sql, false, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $svg->dieSchema( $pageNumber, "SVG", @@ -445,19 +445,19 @@ class Table_Stats ) ); } - list($this->x, $this->y) = PMA_DBI_fetchRow($result); + list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result); $this->x = (double) $this->x; $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $tableName); // index - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE ); - if (PMA_DBI_numRows($result) > 0) { - while ($row = PMA_DBI_fetchAssoc($result)) { + if ($GLOBALS['dbi']->numRows($result) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } diff --git a/libraries/schema/User_Schema.class.php b/libraries/schema/User_Schema.class.php index 2ae422db5c..4d51b57098 100644 --- a/libraries/schema/User_Schema.class.php +++ b/libraries/schema/User_Schema.class.php @@ -185,7 +185,7 @@ class PMA_User_Schema $page_query, false, PMA_DBI_QUERY_STORE ); - if ($page_rs && PMA_DBI_numRows($page_rs) > 0) { + if ($page_rs && $GLOBALS['dbi']->numRows($page_rs) > 0) { ?> <form method="get" action="schema_edit.php" name="frm_select_page"> <fieldset> @@ -197,7 +197,7 @@ class PMA_User_Schema <select name="chpage" id="chpage" class="autosubmit"> <option value="0"><?php echo __('Select page'); ?></option> <?php - while ($curr_page = PMA_DBI_fetchAssoc($page_rs)) { + while ($curr_page = $GLOBALS['dbi']->fetchAssoc($page_rs)) { echo "\n" . ' ' . '<option value="' . $curr_page['page_nr'] . '"'; if (isset($this->chosenPage) @@ -245,12 +245,12 @@ class PMA_User_Schema * We will need an array of all tables in this db */ $selectboxall = array('--'); - $alltab_rs = PMA_DBI_query( + $alltab_rs = $GLOBALS['dbi']->query( 'SHOW TABLES FROM ' . PMA_Util::backquote($db) . ';', null, PMA_DBI_QUERY_STORE ); - while ($val = @PMA_DBI_fetchRow($alltab_rs)) { + while ($val = @$GLOBALS['dbi']->fetchRow($alltab_rs)) { $selectboxall[] = $val[0]; } @@ -271,7 +271,7 @@ class PMA_User_Schema . PMA_Util::sqlAddSlashes($this->chosenPage) . '\''; $page_rs = PMA_queryAsControlUser($page_query, false); $array_sh_page = array(); - while ($temp_sh_page = @PMA_DBI_fetchAssoc($page_rs)) { + while ($temp_sh_page = @$GLOBALS['dbi']->fetchAssoc($page_rs)) { $array_sh_page[] = $temp_sh_page; } /* @@ -427,11 +427,11 @@ class PMA_User_Schema <label for="pdf_page_number_opt"><?php echo __('Page number:'); ?></label> <select name="pdf_page_number" id="pdf_page_number_opt"> <?php - while ($pages = @PMA_DBI_fetchAssoc($test_rs)) { + while ($pages = @$GLOBALS['dbi']->fetchAssoc($test_rs)) { echo ' <option value="' . $pages['page_nr'] . '">' . $pages['page_nr'] . ': ' . htmlspecialchars($pages['page_descr']) . '</option>' . "\n"; } // end while - PMA_DBI_freeResult($test_rs); + $GLOBALS['dbi']->freeResult($test_rs); unset($test_rs); ?> </select><br /> @@ -573,7 +573,7 @@ class PMA_User_Schema . '</u>'; if (isset($with_field_names)) { - $fields = PMA_DBI_getColumns($db, $temp_sh_page['table_name']); + $fields = $GLOBALS['dbi']->getColumns($db, $temp_sh_page['table_name']); // if the table has been dropped from outside phpMyAdmin, // we can no longer obtain its columns list if ($fields) { @@ -638,7 +638,7 @@ class PMA_User_Schema $export_type = 'pdf'; } - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); include "libraries/schema/" . ucfirst($export_type) . "_Relation_Schema.class.php"; @@ -716,7 +716,7 @@ class PMA_User_Schema * and PBXT tables, as this logic is just to put * the tables on the layout, not to determine relations */ - $tables = PMA_DBI_getTablesFull($db); + $tables = $GLOBALS['dbi']->getTablesFull($db); $foreignkey_tables = array(); foreach ($tables as $table_name => $table_properties) { if (PMA_Util::isForeignKeySupported($table_properties['ENGINE'])) { @@ -747,12 +747,12 @@ class PMA_User_Schema $master_tables_rs = PMA_queryAsControlUser( $master_tables, false, PMA_DBI_QUERY_STORE ); - if ($master_tables_rs && PMA_DBI_numRows($master_tables_rs) > 0) { + if ($master_tables_rs && $GLOBALS['dbi']->numRows($master_tables_rs) > 0) { /* first put all the master tables at beginning * of the list, so they are near the center of * the schema */ - while (list(, $master_table) = PMA_DBI_fetchRow($master_tables_rs)) { + while (list(, $master_table) = $GLOBALS['dbi']->fetchRow($master_tables_rs)) { $all_tables[] = $master_table; } @@ -889,7 +889,7 @@ class PMA_User_Schema $test_query, false, PMA_DBI_QUERY_STORE ); //echo $test_query; - if ($test_rs && PMA_DBI_numRows($test_rs) > 0) { + if ($test_rs && $GLOBALS['dbi']->numRows($test_rs) > 0) { if (isset($arrvalue['delete']) && $arrvalue['delete'] == 'y') { $ch_query = 'DELETE FROM ' . PMA_Util::backquote($GLOBALS['cfgRelation']['db']) diff --git a/libraries/schema/Visio_Relation_Schema.class.php b/libraries/schema/Visio_Relation_Schema.class.php index 515af66755..82aa52032e 100644 --- a/libraries/schema/Visio_Relation_Schema.class.php +++ b/libraries/schema/Visio_Relation_Schema.class.php @@ -224,8 +224,8 @@ class Table_Stats $this->_tableName = $tableName; $sql = 'DESCRIBE ' . PMA_Util::backquote($tableName); - $result = PMA_DBI_tryQuery($sql, null, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + $result = $GLOBALS['dbi']->tryQuery($sql, null, PMA_DBI_QUERY_STORE); + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $visio->dieSchema( $pageNumber, "VISIO", @@ -249,7 +249,7 @@ class Table_Stats } $this->fields = array_keys($all_columns); } else { - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { $this->fields[] = $row[0]; } } @@ -275,7 +275,7 @@ class Table_Stats . ' AND pdf_page_number = ' . $pageNumber; $result = PMA_queryAsControlUser($sql, false, PMA_DBI_QUERY_STORE); - if (! $result || ! PMA_DBI_numRows($result)) { + if (! $result || ! $GLOBALS['dbi']->numRows($result)) { $visio->dieSchema( $pageNumber, "VISIO", @@ -285,18 +285,18 @@ class Table_Stats ) ); } - list($this->x, $this->y) = PMA_DBI_fetchRow($result); + list($this->x, $this->y) = $GLOBALS['dbi']->fetchRow($result); $this->x = (double) $this->x; $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $tableName); // index - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($tableName) . ';', null, PMA_DBI_QUERY_STORE ); - if (PMA_DBI_numRows($result) > 0) { - while ($row = PMA_DBI_fetchAssoc($result)) { + if ($GLOBALS['dbi']->numRows($result) > 0) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } diff --git a/libraries/server_common.inc.php b/libraries/server_common.inc.php index 55e584afb8..9f830ba2cc 100644 --- a/libraries/server_common.inc.php +++ b/libraries/server_common.inc.php @@ -32,11 +32,11 @@ $err_url = 'index.php' . $url_query; /** * @global boolean Checks for superuser privileges */ -$is_superuser = PMA_isSuperuser(); +$is_superuser = $GLOBALS['dbi']->isSuperuser(); // now, select the mysql db if ($is_superuser && ! PMA_DRIZZLE) { - PMA_DBI_selectDb('mysql', $userlink); + $GLOBALS['dbi']->selectDb('mysql', $userlink); } /** @@ -44,7 +44,7 @@ if ($is_superuser && ! PMA_DRIZZLE) { */ $binary_logs = PMA_DRIZZLE ? null - : PMA_DBI_fetchResult( + : $GLOBALS['dbi']->fetchResult( 'SHOW MASTER LOGS', 'Log_name', null, diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index 691b2ff36e..2303b50384 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -78,7 +78,7 @@ function PMA_extractPrivInfo($row = '', $enableHTML = false) $grants = PMA_getGrantsArray(); if (! empty($row) && isset($row['Table_priv'])) { - $row1 = PMA_DBI_fetchSingleRow( + $row1 = $GLOBALS['dbi']->fetchSingleRow( 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', 'ASSOC', $GLOBALS['userlink'] ); @@ -388,7 +388,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', $sql_query = PMA_getSqlQueryForDisplayPrivTable( $db, $table, $username, $hostname ); - $row = PMA_DBI_fetchSingleRow($sql_query); + $row = $GLOBALS['dbi']->fetchSingleRow($sql_query); } if (empty($row)) { if ($table == '*') { @@ -397,21 +397,21 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', } elseif ($table == '*') { $sql_query = 'SHOW COLUMNS FROM `mysql`.`db`;'; } - $res = PMA_DBI_query($sql_query); - while ($row1 = PMA_DBI_fetchRow($res)) { + $res = $GLOBALS['dbi']->query($sql_query); + while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { if (substr($row1[0], 0, 4) == 'max_') { $row[$row1[0]] = 0; } else { $row[$row1[0]] = 'N'; } } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); } else { $row = array('Table_priv' => ''); } } if (isset($row['Table_priv'])) { - $row1 = PMA_DBI_fetchSingleRow( + $row1 = $GLOBALS['dbi']->fetchSingleRow( 'SHOW COLUMNS FROM `mysql`.`tables_priv` LIKE \'Table_priv\';', 'ASSOC', $GLOBALS['userlink'] ); @@ -438,7 +438,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', unset($row['Table_priv'], $current_grant, $av_grants, $users_grants); // get columns - $res = PMA_DBI_tryQuery( + $res = $GLOBALS['dbi']->tryQuery( 'SHOW COLUMNS FROM ' . PMA_Util::backquote( PMA_Util::unescapeMysqlWildcards($db) @@ -447,7 +447,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', ); $columns = array(); if ($res) { - while ($row1 = PMA_DBI_fetchRow($res)) { + while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { $columns[$row1[0]] = array( 'Select' => false, 'Insert' => false, @@ -455,7 +455,7 @@ function PMA_getHtmlToDisplayPrivilegesTable($db = '*', 'References' => false ); } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); } unset($res, $row1); } @@ -569,7 +569,7 @@ function PMA_getHtmlForDisplayResourceLimits($row) function PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db, $table, $columns, $row ) { - $res = PMA_DBI_query( + $res = $GLOBALS['dbi']->query( 'SELECT `Column_name`, `Column_priv`' .' FROM `mysql`.`columns_priv`' .' WHERE `User`' @@ -584,13 +584,13 @@ function PMA_getHtmlForTableSpecificPrivileges($username, $hostname, $db, .' = \'' . PMA_Util::sqlAddSlashes($table) . '\';' ); - while ($row1 = PMA_DBI_fetchRow($res)) { + while ($row1 = $GLOBALS['dbi']->fetchRow($res)) { $row1[1] = explode(',', $row1[1]); foreach ($row1[1] as $current) { $columns[$row1[0]][$current] = true; } } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); unset($res, $row1, $current); $html_output = '<input type="hidden" name="grant_count" ' @@ -1084,7 +1084,7 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new') $html_output .= '<span class="options">' . "\n" . ' <select name="pred_hostname" id="select_pred_hostname" ' . 'title="' . __('Host') . '"' . "\n"; - $_current_user = PMA_DBI_fetchValue('SELECT USER();'); + $_current_user = $GLOBALS['dbi']->fetchValue('SELECT USER();'); if (! empty($_current_user)) { $thishost = str_replace( "'", @@ -1243,7 +1243,7 @@ function PMA_getHtmlForDisplayLoginInformationFields($mode = 'new') */ function PMA_getUsernameAndHostnameLength() { - $fields_info = PMA_DBI_getColumns('mysql', 'user', null, true); + $fields_info = $GLOBALS['dbi']->getColumns('mysql', 'user', null, true); $username_length = 16; $hostname_length = 41; foreach ($fields_info as $val) { @@ -1275,7 +1275,7 @@ function PMA_getUsernameAndHostnameLength() */ function PMA_getGrants($user, $host) { - $grants = PMA_DBI_fetchResult( + $grants = $GLOBALS['dbi']->fetchResult( "SHOW GRANTS FOR '" . PMA_Util::sqlAddSlashes($user) . "'@'" . PMA_Util::sqlAddSlashes($host) . "'" @@ -1337,9 +1337,9 @@ function PMA_getMessageForUpdatePassword($err_url, $username, $hostname) . (($_POST['pma_pw'] == '') ? '\'\'' : $hashing_function . '(\'' . PMA_Util::sqlAddSlashes($_POST['pma_pw']) . '\')'); - PMA_DBI_tryQuery($local_query) + $GLOBALS['dbi']->tryQuery($local_query) or PMA_Util::mysqlDie( - PMA_DBI_getError(), $sql_query, false, $err_url + $GLOBALS['dbi']->getError(), $sql_query, false, $err_url ); $message = PMA_Message::success( __('The password for %s was changed successfully.') @@ -1377,8 +1377,8 @@ function PMA_getMessageAndSqlQueryForPrivilegesRevoke($db_and_table, $dbname, . ' FROM \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; - PMA_DBI_query($sql_query0); - if (! PMA_DBI_tryQuery($sql_query1)) { + $GLOBALS['dbi']->query($sql_query0); + if (! $GLOBALS['dbi']->tryQuery($sql_query1)) { // this one may fail, too... $sql_query1 = ''; } @@ -1594,8 +1594,8 @@ function PMA_getHtmlForSpecificDbPrivileges($link_edit, $conditional_class) .' ORDER BY `User` ASC,' .' `Host` ASC,' .' `Db` ASC;'; - $res = PMA_DBI_query($sql_query); - $row = PMA_DBI_fetchAssoc($res); + $res = $GLOBALS['dbi']->query($sql_query); + $row = $GLOBALS['dbi']->fetchAssoc($res); if ($row) { $found = true; } @@ -1660,7 +1660,7 @@ function PMA_getHtmlTableBodyForSpecificDbPrivs($found, $row, $odd_row, && $current_host == $row['Host'] ) { $current_privileges[] = $row; - $row = PMA_DBI_fetchAssoc($res); + $row = $GLOBALS['dbi']->fetchAssoc($res); } $html_output .= '<tr ' . 'class="noclick ' . ($odd_row ? 'odd' : 'even') @@ -1914,8 +1914,8 @@ function PMA_getExtraDataForAjaxBehavior($password, $link_export, $sql_query, if (isset($_REQUEST['validate_username'])) { $sql_query = "SELECT * FROM `mysql`.`user` WHERE `User` = '" . $_REQUEST['username'] . "';"; - $res = PMA_DBI_query($sql_query); - $row = PMA_DBI_fetchRow($res); + $res = $GLOBALS['dbi']->query($sql_query); + $row = $GLOBALS['dbi']->fetchRow($res); if (empty($row)) { $extra_data['user_exists'] = false; } else { @@ -2059,9 +2059,9 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')' .' ORDER BY `' . $dbOrTableName .'` ASC'; - $db_rights_result = PMA_DBI_query($db_rights_sql); + $db_rights_result = $GLOBALS['dbi']->query($db_rights_sql); - while ($db_rights_row = PMA_DBI_fetchAssoc($db_rights_result)) { + while ($db_rights_row = $GLOBALS['dbi']->fetchAssoc($db_rights_result)) { $db_rights_row = array_merge($user_defaults, $db_rights_row); if (! strlen($dbname)) { // only Db names in the table `mysql`.`db` uses wildcards @@ -2074,7 +2074,7 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) $db_rights[$db_rights_row[$dbOrTableName]] = $db_rights_row; } - PMA_DBI_freeResult($db_rights_result); + $GLOBALS['dbi']->freeResult($db_rights_result); if (! strlen($dbname)) { $sql_query = 'SELECT * FROM `mysql`.`db`' @@ -2089,10 +2089,10 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) .' ORDER BY `Table_name` ASC;'; } - $result = PMA_DBI_query($sql_query); + $result = $GLOBALS['dbi']->query($sql_query); $sql_query = ''; - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { if (isset($db_rights[$row[$dbOrTableName]])) { $db_rights[$row[$dbOrTableName]] = array_merge($db_rights[$row[$dbOrTableName]], $row); @@ -2105,7 +2105,7 @@ function PMA_getUserSpecificRights($tables, $user_host_condition, $dbname) $db_rights[$row['Db']]['can_delete'] = true; } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); return $db_rights; } @@ -2133,7 +2133,7 @@ function PMA_getHtmlForDisplayUserRightsInRows($db_rights, $link_edit, $dbname, . '</tr>' . "\n"; } else { $odd_row = true; - //while ($row = PMA_DBI_fetchAssoc($res)) { + //while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { foreach ($db_rights as $row) { $found_rows[] = (! strlen($dbname)) ? $row['Db'] : $row['Table_name']; @@ -2250,7 +2250,7 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname // get data // we also want privielgs for this user not in table `db` but in other table - $tables = PMA_DBI_fetchResult('SHOW TABLES FROM `mysql`;'); + $tables = $GLOBALS['dbi']->fetchResult('SHOW TABLES FROM `mysql`;'); /** * no db name given, so we want all privs for the given user @@ -2282,7 +2282,7 @@ function PMA_getTableForDisplayAllTableSpecificRights($username, $hostname */ function PMA_getHtmlForDisplaySelectDbInEditPrivs($found_rows) { - $pred_db_array = PMA_DBI_fetchResult('SHOW DATABASES;'); + $pred_db_array = $GLOBALS['dbi']->fetchResult('SHOW DATABASES;'); $html_output = '<label for="text_dbname">' . __('Add privileges on the following database:') . '</label>' . "\n"; @@ -2326,7 +2326,7 @@ function PMA_displayTablesInEditPrivs($dbname, $found_rows) $html_output .= '<label for="text_tablename">' . __('Add privileges on the following table:') . '</label>' . "\n"; - $result = @PMA_DBI_tryQuery( + $result = @$GLOBALS['dbi']->tryQuery( 'SHOW TABLES FROM ' . PMA_Util::backquote( PMA_Util::unescapeMysqlWildcards($dbname) ) . ';', @@ -2336,12 +2336,12 @@ function PMA_displayTablesInEditPrivs($dbname, $found_rows) if ($result) { $pred_tbl_array = array(); - while ($row = PMA_DBI_fetchRow($result)) { + while ($row = $GLOBALS['dbi']->fetchRow($result)) { if (! isset($found_rows) || ! in_array($row[0], $found_rows)) { $pred_tbl_array[] = $row[0]; } } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); if (! empty($pred_tbl_array)) { $html_output .= '<select name="pred_tablename" ' @@ -2380,11 +2380,11 @@ function PMA_displayTablesInEditPrivs($dbname, $found_rows) function PMA_getUsersOverview($result, $db_rights, $link_edit, $pmaThemeImage, $text_dir, $conditional_class, $link_export ) { - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { $row['privs'] = PMA_extractPrivInfo($row, true); $db_rights[$row['User']][$row['Host']] = $row; } - @PMA_DBI_freeResult($result); + @$GLOBALS['dbi']->freeResult($result); $html_output = '<form name="usersForm" id="usersForm" action="server_privileges.php" ' @@ -2585,12 +2585,12 @@ function PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class) } } - $initials = PMA_DBI_tryQuery( + $initials = $GLOBALS['dbi']->tryQuery( 'SELECT DISTINCT UPPER(LEFT(`User`,1)) FROM `user` ORDER BY `User` ASC', null, PMA_DBI_QUERY_STORE ); - while (list($tmp_initial) = PMA_DBI_fetchRow($initials)) { + while (list($tmp_initial) = $GLOBALS['dbi']->fetchRow($initials)) { $array_initials[$tmp_initial] = true; } @@ -2634,7 +2634,7 @@ function PMA_getHtmlForDisplayTheInitials($array_initials, $conditional_class) function PMA_getDbRightsForUserOverview() { // we also want users not in table `user` but in other table - $tables = PMA_DBI_fetchResult('SHOW TABLES FROM `mysql`;'); + $tables = $GLOBALS['dbi']->fetchResult('SHOW TABLES FROM `mysql`;'); $tables_to_search_for_users = array( 'user', 'db', 'tables_priv', 'columns_priv', 'procs_priv', @@ -2662,14 +2662,14 @@ function PMA_getDbRightsForUserOverview() $db_rights_sql = '(' . implode(') UNION (', $db_rights_sqls) . ')' .' ORDER BY `User` ASC, `Host` ASC'; - $db_rights_result = PMA_DBI_query($db_rights_sql); + $db_rights_result = $GLOBALS['dbi']->query($db_rights_sql); - while ($db_rights_row = PMA_DBI_fetchAssoc($db_rights_result)) { + while ($db_rights_row = $GLOBALS['dbi']->fetchAssoc($db_rights_result)) { $db_rights_row = array_merge($user_defaults, $db_rights_row); $db_rights[$db_rights_row['User']][$db_rights_row['Host']] = $db_rights_row; } - PMA_DBI_freeResult($db_rights_result); + $GLOBALS['dbi']->freeResult($db_rights_result); ksort($db_rights); return $db_rights; @@ -2694,8 +2694,8 @@ function PMA_deleteUser($queries) $drop_user_error = ''; foreach ($queries as $sql_query) { if ($sql_query{0} != '#') { - if (! PMA_DBI_tryQuery($sql_query, $GLOBALS['userlink'])) { - $drop_user_error .= PMA_DBI_getError() . "\n"; + if (! $GLOBALS['dbi']->tryQuery($sql_query, $GLOBALS['userlink'])) { + $drop_user_error .= $GLOBALS['dbi']->getError() . "\n"; } } } @@ -2757,18 +2757,18 @@ function PMA_updatePrivileges($username, $hostname, $tablename, $dbname) } $sql_query2 .= ';'; } - if (! PMA_DBI_tryQuery($sql_query0)) { + if (! $GLOBALS['dbi']->tryQuery($sql_query0)) { // This might fail when the executing user does not have // ALL PRIVILEGES himself. // See https://sourceforge.net/p/phpmyadmin/bugs/3270/ $sql_query0 = ''; } - if (isset($sql_query1) && ! PMA_DBI_tryQuery($sql_query1)) { + if (isset($sql_query1) && ! $GLOBALS['dbi']->tryQuery($sql_query1)) { // this one may fail, too... $sql_query1 = ''; } if (isset($sql_query2)) { - PMA_DBI_query($sql_query2); + $GLOBALS['dbi']->query($sql_query2); } else { $sql_query2 = ''; } @@ -2924,7 +2924,7 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage, : ''); $sql_query .= ' ORDER BY `User` ASC, `Host` ASC;'; - $res = PMA_DBI_tryQuery($sql_query, null, PMA_DBI_QUERY_STORE); + $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DBI_QUERY_STORE); if (! $res) { // the query failed! This may have two reasons: @@ -2933,11 +2933,11 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage, // so let's try a more simple query $sql_query = 'SELECT * FROM `mysql`.`user`'; - $res = PMA_DBI_tryQuery($sql_query, null, PMA_DBI_QUERY_STORE); + $res = $GLOBALS['dbi']->tryQuery($sql_query, null, PMA_DBI_QUERY_STORE); if (! $res) { $html_output .= PMA_Message::error(__('No Privileges'))->getDisplay(); - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); unset($res); } else { // This message is hardcoded because I will replace it by @@ -2959,7 +2959,7 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage, * Displays the initials * Also not necassary if there is less than 20 privileges */ - if (PMA_DBI_numRows($res) > 20 ) { + if ($GLOBALS['dbi']->numRows($res) > 20 ) { $html_output .= PMA_getHtmlForDisplayTheInitials( $array_initials, $conditional_class ); @@ -2971,7 +2971,7 @@ function PMA_getHtmlForDisplayUserOverviewPage($link_edit, $pmaThemeImage, */ if (isset($_REQUEST['initial']) || isset($_REQUEST['showall']) - || PMA_DBI_numRows($res) < 50 + || $GLOBALS['dbi']->numRows($res) < 50 ) { $html_output .= PMA_getUsersOverview( $res, $db_rights, $link_edit, $pmaThemeImage, @@ -3025,7 +3025,7 @@ function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard,$url_dbname, . " WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'" . " AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "';"; - $user_does_not_exists = (bool) ! PMA_DBI_fetchValue($sql); + $user_does_not_exists = (bool) ! $GLOBALS['dbi']->fetchValue($sql); if ($user_does_not_exists) { $html_output .= PMA_Message::error( @@ -3115,14 +3115,14 @@ function PMA_getHtmlForDisplayUserProperties($dbname_is_wildcard,$url_dbname, function PMA_getTablePrivsQueriesForChangeOrCopyUser($user_host_condition, $queries, $username, $hostname ) { - $res = PMA_DBI_query( + $res = $GLOBALS['dbi']->query( 'SELECT `Db`, `Table_name`, `Table_priv` FROM `mysql`.`tables_priv`' . $user_host_condition, $GLOBALS['userlink'], PMA_DBI_QUERY_STORE ); - while ($row = PMA_DBI_fetchAssoc($res)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { - $res2 = PMA_DBI_QUERY( + $res2 = $GLOBALS['dbi']->query( 'SELECT `Column_name`, `Column_priv`' .' FROM `mysql`.`columns_priv`' .' WHERE `User`' @@ -3146,7 +3146,7 @@ function PMA_getTablePrivsQueriesForChangeOrCopyUser($user_host_condition, 'References' => array() ); - while ($row2 = PMA_DBI_fetchAssoc($res2)) { + while ($row2 = $GLOBALS['dbi']->fetchAssoc($res2)) { $tmp_array = explode(',', $row2['Column_priv']); if (in_array('Select', $tmp_array)) { $tmp_privs2['Select'][] = $row2['Column_name']; @@ -3201,16 +3201,16 @@ function PMA_getDbSpecificPrivsQueriesForChangeOrCopyUser( .' AND `Host`' .' = \'' . PMA_Util::sqlAddSlashes($_REQUEST['old_username']) . '\';'; - $res = PMA_DBI_query('SELECT * FROM `mysql`.`db`' . $user_host_condition); + $res = $GLOBALS['dbi']->query('SELECT * FROM `mysql`.`db`' . $user_host_condition); - while ($row = PMA_DBI_fetchAssoc($res)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($res)) { $queries[] = 'GRANT ' . join(', ', PMA_extractPrivInfo($row)) .' ON ' . PMA_Util::backquote($row['Db']) . '.*' .' TO \'' . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\'' . ($row['Grant_priv'] == 'Y' ? ' WITH GRANT OPTION;' : ';'); } - PMA_DBI_freeResult($res); + $GLOBALS['dbi']->freeResult($res); $queries = PMA_getTablePrivsQueriesForChangeOrCopyUser( $user_host_condition, $queries, $username, $hostname @@ -3235,10 +3235,10 @@ function PMA_getDbSpecificPrivsQueriesForChangeOrCopyUser( function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, $username, $hostname, $dbname ) { - if ($_error || ! PMA_DBI_tryQuery($real_sql_query)) { + if ($_error || ! $GLOBALS['dbi']->tryQuery($real_sql_query)) { $_REQUEST['createdb-1'] = $_REQUEST['createdb-2'] = $_REQUEST['createdb-3'] = false; - $message = PMA_Message::rawError(PMA_DBI_getError()); + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } else { $message = PMA_Message::success(__('You have added a new user.')); } @@ -3250,8 +3250,8 @@ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, PMA_Util::sqlAddSlashes($username) ) . ';'; $sql_query .= $q; - if (! PMA_DBI_tryQuery($q)) { - $message = PMA_Message::rawError(PMA_DBI_getError()); + if (! $GLOBALS['dbi']->tryQuery($q)) { + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } /** @@ -3269,8 +3269,8 @@ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; - if (! PMA_DBI_tryQuery($q)) { - $message = PMA_Message::rawError(PMA_DBI_getError()); + if (! $GLOBALS['dbi']->tryQuery($q)) { + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } } @@ -3283,8 +3283,8 @@ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; - if (! PMA_DBI_tryQuery($q)) { - $message = PMA_Message::rawError(PMA_DBI_getError()); + if (! $GLOBALS['dbi']->tryQuery($q)) { + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } } @@ -3297,8 +3297,8 @@ function PMA_addUserAndCreateDatabase($_error, $real_sql_query, $sql_query, . PMA_Util::sqlAddSlashes($username) . '\'@\'' . PMA_Util::sqlAddSlashes($hostname) . '\';'; $sql_query .= $q; - if (! PMA_DBI_tryQuery($q)) { - $message = PMA_Message::rawError(PMA_DBI_getError()); + if (! $GLOBALS['dbi']->tryQuery($q)) { + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } } return array($sql_query, $message); diff --git a/libraries/sql.lib.php b/libraries/sql.lib.php index b7b42385f7..e868c07cb7 100644 --- a/libraries/sql.lib.php +++ b/libraries/sql.lib.php @@ -130,14 +130,14 @@ function getTableHtmlForMultipleQueries( ) { $table_html = ''; - $tables_array = PMA_DBI_getTables($db); - $databases_array = PMA_DBI_getDatabasesFull(); + $tables_array = $GLOBALS['dbi']->getTables($db); + $databases_array = $GLOBALS['dbi']->getDatabasesFull(); $multi_sql = implode(";", $sql_data['valid_sql']); $querytime_before = array_sum(explode(' ', microtime())); // Assignment for variable is not needed since the results are // looiping using the connection - @PMA_DBI_tryMultiQuery($multi_sql); + @$GLOBALS['dbi']->tryMultiQuery($multi_sql); $querytime_after = array_sum(explode(' ', microtime())); $querytime = $querytime_after - $querytime_before; @@ -147,9 +147,9 @@ function getTableHtmlForMultipleQueries( $analyzed_sql = array(); $is_affected = false; - $result = PMA_DBI_storeResult(); + $result = $GLOBALS['dbi']->storeResult(); $fields_meta = ($result !== false) - ? PMA_DBI_getFieldsMeta($result) + ? $GLOBALS['dbi']->getFieldsMeta($result) : array(); $fields_cnt = count($fields_meta); @@ -221,9 +221,9 @@ function getTableHtmlForMultipleQueries( } if (! $is_affected) { - $num_rows = ($result) ? @PMA_DBI_numRows($result) : 0; + $num_rows = ($result) ? @$GLOBALS['dbi']->numRows($result) : 0; } elseif (! isset($num_rows)) { - $num_rows = @PMA_DBI_affectedRows(); + $num_rows = @$GLOBALS['dbi']->affectedRows(); } if (isset($sql_data['valid_sql'][$sql_no])) { @@ -254,11 +254,11 @@ function getTableHtmlForMultipleQueries( ); // Free the result to save the memory - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); $sql_no++; - } while (PMA_DBI_moreResults() && PMA_DBI_nextResult()); + } while ($GLOBALS['dbi']->moreResults() && $GLOBALS['dbi']->nextResult()); return $table_html; } @@ -601,9 +601,9 @@ function PMA_getHtmlForSetColumn($db, $table, $column, $curr_value) */ function PMA_getValuesForColumn($db, $table, $column) { - $field_info_query = PMA_DBI_getColumnsSql($db, $table, $column); + $field_info_query = $GLOBALS['dbi']->getColumnsSql($db, $table, $column); - $field_info_result = PMA_DBI_fetchResult( + $field_info_result = $GLOBALS['dbi']->fetchResult( $field_info_query, null, null, null, PMA_DBI_QUERY_STORE ); diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index 7d9f523538..d1fdc56e23 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -218,7 +218,7 @@ function PMA_sqlQueryFormInsert( // Get the list and number of fields // we do a try_query here, because we could be in the query window, // trying to synchonize and the table has not yet been created - $fields_list = PMA_DBI_getColumns($db, $GLOBALS['table'], null, true); + $fields_list = $GLOBALS['dbi']->getColumns($db, $GLOBALS['table'], null, true); $tmp_db_link = '<a href="' . $GLOBALS['cfg']['DefaultTabDatabase'] . '?' . PMA_generate_common_url($db) . '"'; diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index cd6ef34f33..8dec651a46 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -189,7 +189,7 @@ function PMA_getHtmlBodyForTableSummary($num_tables, $server_slave_status, . '</th>'; if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) { - $default_engine = PMA_DBI_fetchValue( + $default_engine = $GLOBALS['dbi']->fetchValue( 'SHOW VARIABLES LIKE \'storage_engine\';', 0, 1 @@ -1445,7 +1445,7 @@ function PMA_getHtmlDivForMoveColumnsDialog() */ function PMA_getHtmlForEditView($url_params) { - $create_view = PMA_DBI_getDefinition( + $create_view = $GLOBALS['dbi']->getDefinition( $GLOBALS['db'], 'VIEW', $GLOBALS['table'] ); $create_view = preg_replace('@^CREATE@', 'ALTER', $create_view); @@ -2231,7 +2231,7 @@ function PMA_displayHtmlForColumnChange($db, $table, $selected, $action) * @todo optimize in case of multiple fields to modify */ for ($i = 0; $i < $selected_cnt; $i++) { - $fields_meta[] = PMA_DBI_getColumns($db, $table, $selected[$i], true); + $fields_meta[] = $GLOBALS['dbi']->getColumns($db, $table, $selected[$i], true); } $num_fields = count($fields_meta); // set these globals because tbl_columns_definition_form.inc.php @@ -2248,14 +2248,14 @@ function PMA_displayHtmlForColumnChange($db, $table, $selected, $action) // could be executed to replace the info given by SHOW FULL COLUMNS FROM. /** * @todo put this code into a require() - * or maybe make it part of PMA_DBI_getColumns(); + * or maybe make it part of $GLOBALS['dbi']->getColumns(); */ // We also need this to correctly learn if a TIMESTAMP is NOT NULL, since // SHOW FULL COLUMNS says NULL and SHOW CREATE TABLE says NOT NULL (tested // in MySQL 4.0.25). - $show_create_table = PMA_DBI_fetchValue( + $show_create_table = $GLOBALS['dbi']->fetchValue( 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1 ); @@ -2338,9 +2338,9 @@ function PMA_updateColumns($db, $table) // To allow replication, we first select the db to use and then run queries // on this db. - if (! PMA_DBI_selectDb($db)) { + if (! $GLOBALS['dbi']->selectDb($db)) { PMA_Util::mysqlDie( - PMA_DBI_getError(), + $GLOBALS['dbi']->getError(), 'USE ' . PMA_Util::backquote($db) . ';', '', $err_url @@ -2349,7 +2349,7 @@ function PMA_updateColumns($db, $table) $sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' '; $sql_query .= implode(', ', $changes) . $key_query; $sql_query .= ';'; - $result = PMA_DBI_tryQuery($sql_query); + $result = $GLOBALS['dbi']->tryQuery($sql_query); $response = PMA_Response::getInstance(); if ($result !== false) { @@ -2402,7 +2402,7 @@ function PMA_updateColumns($db, $table) $response->isSuccess(false); $response->addJSON( 'message', - PMA_Message::rawError(__('Query error') . ':<br />'.PMA_DBI_getError()) + PMA_Message::rawError(__('Query error') . ':<br />'.$GLOBALS['dbi']->getError()) ); $regenerate = true; } @@ -2419,12 +2419,12 @@ function PMA_updateColumns($db, $table) */ function PMA_moveColumns($db, $table) { - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); /* * load the definitions for all columns */ - $columns = PMA_DBI_getColumnsFull($db, $table); + $columns = $GLOBALS['dbi']->getColumnsFull($db, $table); $column_names = array_keys($columns); $changes = array(); $we_dont_change_keys = array(); @@ -2491,8 +2491,8 @@ function PMA_moveColumns($db, $table) $move_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' '; $move_query .= implode(', ', $changes); // move columns - $result = PMA_DBI_tryQuery($move_query); - $tmp_error = PMA_DBI_getError(); + $result = $GLOBALS['dbi']->tryQuery($move_query); + $tmp_error = $GLOBALS['dbi']->getError(); if ($tmp_error) { $response->isSuccess(false); $response->addJSON('message', PMA_Message::error($tmp_error)); diff --git a/libraries/tbl_columns_definition_form.inc.php b/libraries/tbl_columns_definition_form.inc.php index f5580b8fdb..bc158e43a0 100644 --- a/libraries/tbl_columns_definition_form.inc.php +++ b/libraries/tbl_columns_definition_form.inc.php @@ -142,8 +142,8 @@ if (isset($fields_meta)) { . '.' . PMA_Util::backquote($table) . ' LIMIT 1'; - $move_columns_sql_result = PMA_DBI_tryQuery($move_columns_sql_query); - $move_columns = PMA_DBI_getFieldsMeta($move_columns_sql_result); + $move_columns_sql_result = $GLOBALS['dbi']->tryQuery($move_columns_sql_query); + $move_columns = $GLOBALS['dbi']->getFieldsMeta($move_columns_sql_result); unset($move_columns_sql_query, $move_columns_sql_result); $header_cells[] = __('Move column'); diff --git a/libraries/tbl_common.inc.php b/libraries/tbl_common.inc.php index 0a592fccd7..ae8c4e74b8 100644 --- a/libraries/tbl_common.inc.php +++ b/libraries/tbl_common.inc.php @@ -17,7 +17,7 @@ require_once './libraries/bookmark.lib.php'; // Check parameters PMA_Util::checkParameters(array('db', 'table')); -$db_is_information_schema = PMA_isSystemSchema($db); +$db_is_information_schema = $GLOBALS['dbi']->isSystemSchema($db); /** * Set parameters for links diff --git a/libraries/tbl_info.inc.php b/libraries/tbl_info.inc.php index 10a9ed5e65..c1ed2cd75e 100644 --- a/libraries/tbl_info.inc.php +++ b/libraries/tbl_info.inc.php @@ -26,7 +26,7 @@ global $showtable, $tbl_is_view, $tbl_storage_engine, $show_comment, $tbl_collat */ // Seems we need to do this in MySQL 5.0.2, // otherwise error #1046, no database selected -PMA_DBI_selectDb($GLOBALS['db']); +$GLOBALS['dbi']->selectDb($GLOBALS['db']); /** diff --git a/libraries/tbl_views.lib.php b/libraries/tbl_views.lib.php index 60b1645a9a..98bcdc19a8 100644 --- a/libraries/tbl_views.lib.php +++ b/libraries/tbl_views.lib.php @@ -23,11 +23,11 @@ function PMA_getColumnMap($sql_query, $view_columns) $column_map = array(); // Select query which give results for VIEW - $real_source_result = PMA_DBI_tryQuery($sql_query); + $real_source_result = $GLOBALS['dbi']->tryQuery($sql_query); if ($real_source_result !== false) { - $real_source_fields_meta = PMA_DBI_getFieldsMeta($real_source_result); + $real_source_fields_meta = $GLOBALS['dbi']->getFieldsMeta($real_source_result); if (count($real_source_fields_meta) > 0) { @@ -75,7 +75,7 @@ function PMA_getExistingTranformationData($db) . ' WHERE `db_name` = \'' . PMA_Util::sqlAddSlashes($db) . '\''; - return PMA_DBI_tryQuery($pma_transformation_sql); + return $GLOBALS['dbi']->tryQuery($pma_transformation_sql); } @@ -106,7 +106,7 @@ function PMA_getNewTransformationDataSql( $column_count = 0; $add_comma = false; - while ($data_row = PMA_DBI_fetchAssoc($pma_tranformation_data)) { + while ($data_row = $GLOBALS['dbi']->fetchAssoc($pma_tranformation_data)) { foreach ($column_map as $column) { diff --git a/libraries/transformations.lib.php b/libraries/transformations.lib.php index 921063e6b1..5215cc21fc 100644 --- a/libraries/transformations.lib.php +++ b/libraries/transformations.lib.php @@ -184,7 +184,7 @@ function PMA_getMIME($db, $table, $strict = false) AND ( `mimetype` != \'\'' . (!$strict ? ' OR `transformation` != \'\' OR `transformation_options` != \'\'' : '') . ')'; - $result = PMA_DBI_fetchResult( + $result = $GLOBALS['dbi']->fetchResult( $com_qry, 'column_name', null, $GLOBALS['controllink'] ); @@ -282,9 +282,9 @@ function PMA_setMIME($db, $table, $key, $mimetype, $transformation, $test_rs = PMA_queryAsControlUser($test_qry, true, PMA_DBI_QUERY_STORE); - if ($test_rs && PMA_DBI_numRows($test_rs) > 0) { - $row = @PMA_DBI_fetchAssoc($test_rs); - PMA_DBI_freeResult($test_rs); + if ($test_rs && $GLOBALS['dbi']->numRows($test_rs) > 0) { + $row = @$GLOBALS['dbi']->fetchAssoc($test_rs); + $GLOBALS['dbi']->freeResult($test_rs); if (! $forcedelete && (strlen($mimetype) || strlen($transformation) @@ -405,7 +405,7 @@ function PMA_clearTransformations($db, $table = '', $column = '') $delete_sql .= '`db_name` = \'' . $db . '\' '; } - return PMA_DBI_tryQuery($delete_sql); + return $GLOBALS['dbi']->tryQuery($delete_sql); } diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php index 20028348e4..8697a75b8b 100644 --- a/libraries/user_preferences.lib.php +++ b/libraries/user_preferences.lib.php @@ -61,7 +61,7 @@ function PMA_loadUserprefs() SELECT `config_data`, UNIX_TIMESTAMP(`timevalue`) ts FROM ' . $query_table . ' WHERE `username` = \'' . PMA_Util::sqlAddSlashes($cfgRelation['user']) . '\''; - $row = PMA_DBI_fetchSingleRow($query, 'ASSOC', $GLOBALS['controllink']); + $row = $GLOBALS['dbi']->fetchSingleRow($query, 'ASSOC', $GLOBALS['controllink']); return array( 'config_data' => $row ? (array)json_decode($row['config_data']) : array(), @@ -102,7 +102,7 @@ function PMA_saveUserprefs(array $config_array) FROM ' . $query_table . ' WHERE `username` = \'' . PMA_Util::sqlAddSlashes($cfgRelation['user']) . '\''; - $has_config = PMA_DBI_fetchValue($query, 0, 0, $GLOBALS['controllink']); + $has_config = $GLOBALS['dbi']->fetchValue($query, 0, 0, $GLOBALS['controllink']); $config_data = json_encode($config_array); if ($has_config) { $query = ' @@ -118,11 +118,11 @@ function PMA_saveUserprefs(array $config_array) if (isset($_SESSION['cache'][$cache_key]['userprefs'])) { unset($_SESSION['cache'][$cache_key]['userprefs']); } - if (!PMA_DBI_tryQuery($query, $GLOBALS['controllink'])) { + if (!$GLOBALS['dbi']->tryQuery($query, $GLOBALS['controllink'])) { $message = PMA_Message::error(__('Could not save configuration')); $message->addMessage('<br /><br />'); $message->addMessage( - PMA_Message::rawError(PMA_DBI_getError($GLOBALS['controllink'])) + PMA_Message::rawError($GLOBALS['dbi']->getError($GLOBALS['controllink'])) ); return $message; } diff --git a/pmd_pdf.php b/pmd_pdf.php index bdfcc00810..05c7a7148e 100644 --- a/pmd_pdf.php +++ b/pmd_pdf.php @@ -109,11 +109,11 @@ $table_info_result = PMA_queryAsControlUser( . ' WHERE db_name = \'' . PMA_Util::sqlAddSlashes($db) . '\'' ); -if (PMA_DBI_numRows($table_info_result) > 0) { +if ($GLOBALS['dbi']->numRows($table_info_result) > 0) { echo '<p>' . __('Page:'); echo '<select name="pdf_page_number">'; - while ($page = PMA_DBI_fetchAssoc($table_info_result)) { + while ($page = $GLOBALS['dbi']->fetchAssoc($table_info_result)) { echo '<option value="' . $page['page_nr'] . '">'; echo htmlspecialchars($page['page_descr']); echo '</option>'; diff --git a/pmd_relation_new.php b/pmd_relation_new.php index cff413fb62..953f412ccd 100644 --- a/pmd_relation_new.php +++ b/pmd_relation_new.php @@ -17,9 +17,9 @@ $die_save_pos = 0; require_once 'pmd_save_pos.php'; extract($_POST, EXTR_SKIP); -$tables = PMA_DBI_getTablesFull($db, $T1); +$tables = $GLOBALS['dbi']->getTablesFull($db, $T1); $type_T1 = strtoupper($tables[$T1]['ENGINE']); -$tables = PMA_DBI_getTablesFull($db, $T2); +$tables = $GLOBALS['dbi']->getTablesFull($db, $T2); $type_T2 = strtoupper($tables[$T2]['ENGINE']); // native foreign key @@ -37,25 +37,25 @@ if (PMA_Util::isForeignKeySupported($type_T1) // note: in InnoDB, the index does not requires to be on a PRIMARY // or UNIQUE key // improve: check all other requirements for InnoDB relations - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($T1) . ';' ); $index_array1 = array(); // will be use to emphasis prim. keys in the table view - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { $index_array1[$row['Column_name']] = 1; } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SHOW INDEX FROM ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($T2) . ';' ); $index_array2 = array(); // will be used to emphasis prim. keys in the table view - while ($row = PMA_DBI_fetchAssoc($result)) { + while ($row = $GLOBALS['dbi']->fetchAssoc($result)) { $index_array2[$row['Column_name']] = 1; } - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); if (! empty($index_array1[$F1]) && ! empty($index_array2[$F2])) { $upd_query = 'ALTER TABLE ' . PMA_Util::backquote($db) @@ -74,7 +74,7 @@ if (PMA_Util::isForeignKeySupported($type_T1) $upd_query .= ' ON UPDATE ' . $on_update; } $upd_query .= ';'; - PMA_DBI_tryQuery($upd_query) or PMD_return_new(0, __('Error: Relation not added.')); + $GLOBALS['dbi']->tryQuery($upd_query) or PMD_return_new(0, __('Error: Relation not added.')); PMD_return_new(1, __('FOREIGN KEY relation added')); } } else { // internal (pmadb) relation diff --git a/pmd_relation_upd.php b/pmd_relation_upd.php index 304169cb5d..743f50b79e 100644 --- a/pmd_relation_upd.php +++ b/pmd_relation_upd.php @@ -20,9 +20,9 @@ require_once 'pmd_save_pos.php'; list($DB1, $T1) = explode(".", $T1); list($DB2, $T2) = explode(".", $T2); -$tables = PMA_DBI_getTablesFull($db, $T1); +$tables = $GLOBALS['dbi']->getTablesFull($db, $T1); $type_T1 = strtoupper($tables[$T1]['ENGINE']); -$tables = PMA_DBI_getTablesFull($db, $T2); +$tables = $GLOBALS['dbi']->getTablesFull($db, $T2); $type_T2 = strtoupper($tables[$T2]['ENGINE']); $try_to_delete_internal_relation = false; @@ -39,7 +39,7 @@ if (PMA_Util::isForeignKeySupported($type_T1) . '.' . PMA_Util::backquote($T2) . ' DROP FOREIGN KEY ' . PMA_Util::backquote($existrel_foreign[$F2]['constraint']) . ';'; - $upd_rs = PMA_DBI_query($upd_query); + $upd_rs = $GLOBALS['dbi']->query($upd_query); } else { // there can be an internal relation even if InnoDB $try_to_delete_internal_relation = true; diff --git a/querywindow.php b/querywindow.php index 805b0b34d3..551176b677 100644 --- a/querywindow.php +++ b/querywindow.php @@ -12,7 +12,7 @@ */ require_once 'libraries/common.inc.php'; -$is_superuser = PMA_isSuperuser(); +$is_superuser = $GLOBALS['dbi']->isSuperuser(); /** * Gets a core script and starts output buffering work diff --git a/server_binlog.php b/server_binlog.php index bc86a7e2dd..8fdb76fc96 100644 --- a/server_binlog.php +++ b/server_binlog.php @@ -48,14 +48,14 @@ if ($GLOBALS['cfg']['MaxRows'] !== 'all') { /** * Sends the query */ -$result = PMA_DBI_query($sql_query); +$result = $GLOBALS['dbi']->query($sql_query); /** * prepare some vars for displaying the result table */ // Gets the list of fields properties if (isset($result) && $result) { - $num_rows = PMA_DBI_numRows($result); + $num_rows = $GLOBALS['dbi']->numRows($result); } else { $num_rows = 0; } @@ -194,7 +194,7 @@ $html .= '</td>' . '<tbody>'; $odd_row = true; -while ($value = PMA_DBI_fetchAssoc($result)) { +while ($value = $GLOBALS['dbi']->fetchAssoc($result)) { if (! $dontlimitchars && PMA_strlen($value['Info']) > $GLOBALS['cfg']['LimitChars'] ) { diff --git a/server_databases.php b/server_databases.php index f67f94a472..9b16568b3b 100644 --- a/server_databases.php +++ b/server_databases.php @@ -152,7 +152,7 @@ if ($cfg['ShowCreateDb']) { * Gets the databases list */ if ($server > 0) { - $databases = PMA_DBI_getDatabasesFull( + $databases = $GLOBALS['dbi']->getDatabasesFull( null, $dbstats, null, $sort_by, $sort_order, $pos, true ); $databases_count = count($GLOBALS['pma']->databases); @@ -244,7 +244,7 @@ if ($databases_count > 0) { $odd_row = true; foreach ($databases as $current) { $tr_class = $odd_row ? 'odd' : 'even'; - if (PMA_isSystemSchema($current['SCHEMA_NAME'], true)) { + if ($GLOBALS['dbi']->isSystemSchema($current['SCHEMA_NAME'], true)) { $tr_class .= ' noclick'; } $html .= '<tr class="' . $tr_class . '">' . "\n"; diff --git a/server_privileges.php b/server_privileges.php index eb7ae58b98..4c9d84f842 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -158,7 +158,7 @@ if (isset($_REQUEST['change_copy'])) { . "'". PMA_Util::sqlAddSlashes($_REQUEST['old_username']) . "'" . ' AND `Host` = ' . "'" . PMA_Util::sqlAddSlashes($_REQUEST['old_hostname']) . "';"; - $row = PMA_DBI_fetchSingleRow( + $row = $GLOBALS['dbi']->fetchSingleRow( 'SELECT * FROM `mysql`.`user` ' . $user_host_condition ); if (! $row) { @@ -196,7 +196,7 @@ if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) { $hostname = ''; break; case 'thishost': - $_user_name = PMA_DBI_fetchValue('SELECT USER()'); + $_user_name = $GLOBALS['dbi']->fetchValue('SELECT USER()'); $hostname = substr($_user_name, (strrpos($_user_name, '@') + 1)); unset($_user_name); break; @@ -204,7 +204,7 @@ if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) { $sql = "SELECT '1' FROM `mysql`.`user`" . " WHERE `User` = '" . PMA_Util::sqlAddSlashes($username) . "'" . " AND `Host` = '" . PMA_Util::sqlAddSlashes($hostname) . "';"; - if (PMA_DBI_fetchValue($sql) == 1) { + if ($GLOBALS['dbi']->fetchValue($sql) == 1) { $message = PMA_Message::error(__('The user %s already exists!')); $message->addParam('[em]\'' . $username . '\'@\'' . $hostname . '\'[/em]'); $_REQUEST['adduser'] = true; @@ -219,7 +219,7 @@ if (isset($_REQUEST['adduser_submit']) || isset($_REQUEST['change_copy'])) { $_error = false; if (isset($create_user_real)) { - if (! PMA_DBI_tryQuery($create_user_real)) { + if (! $GLOBALS['dbi']->tryQuery($create_user_real)) { $_error = true; } $sql_query = $create_user_show . $sql_query; @@ -334,7 +334,7 @@ if (isset($_REQUEST['change_copy'])) { $tmp_count = 0; foreach ($queries as $sql_query) { if ($sql_query{0} != '#') { - PMA_DBI_query($sql_query); + $GLOBALS['dbi']->query($sql_query); } // when there is a query containing a hidden password, take it // instead of the real query sent @@ -352,7 +352,7 @@ if (isset($_REQUEST['change_copy'])) { */ if (isset($_REQUEST['flush_privileges'])) { $sql_query = 'FLUSH PRIVILEGES;'; - PMA_DBI_query($sql_query); + $GLOBALS['dbi']->query($sql_query); $message = PMA_Message::success(__('The privileges were reloaded successfully.')); } diff --git a/server_replication.php b/server_replication.php index ab18c22255..d119ab3e7d 100644 --- a/server_replication.php +++ b/server_replication.php @@ -114,7 +114,7 @@ if (isset($GLOBALS['sr_take_action'])) { } elseif (isset($GLOBALS['sr_slave_server_control'])) { if ($GLOBALS['sr_slave_action'] == 'reset') { PMA_Replication_Slave_control("STOP"); - PMA_DBI_tryQuery("RESET SLAVE;"); + $GLOBALS['dbi']->tryQuery("RESET SLAVE;"); PMA_Replication_Slave_control("START"); } else { PMA_Replication_Slave_control( @@ -130,7 +130,7 @@ if (isset($GLOBALS['sr_take_action'])) { $count = $GLOBALS['sr_skip_errors_count'] * 1; } PMA_Replication_Slave_control("STOP"); - PMA_DBI_tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";"); + $GLOBALS['dbi']->tryQuery("SET GLOBAL SQL_SLAVE_SKIP_COUNTER = ".$count.";"); PMA_Replication_Slave_control("START"); } diff --git a/server_status.php b/server_status.php index ff9026778a..6e81e70f06 100644 --- a/server_status.php +++ b/server_status.php @@ -27,7 +27,7 @@ $ServerStatusData = new PMA_ServerStatusData(); * Kills a selected process */ if (! empty($_REQUEST['kill'])) { - if (PMA_DBI_tryQuery('KILL ' . $_REQUEST['kill'] . ';')) { + if ($GLOBALS['dbi']->tryQuery('KILL ' . $_REQUEST['kill'] . ';')) { $message = PMA_Message::success(__('Thread %s was successfully killed.')); } else { $message = PMA_Message::error( @@ -84,7 +84,7 @@ function PMA_getServerTrafficHtml($ServerStatusData) */ function PMA_getServerStateGeneralInfoHtml($ServerStatusData) { - $start_time = PMA_DBI_fetchValue( + $start_time = $GLOBALS['dbi']->fetchValue( 'SELECT UNIX_TIMESTAMP() - ' . $ServerStatusData->status['Uptime'] ); @@ -427,7 +427,7 @@ function PMA_getTableProcesslistHtml($ServerStatusData) } } - $result = PMA_DBI_query($sql_query); + $result = $GLOBALS['dbi']->query($sql_query); $retval = '<table id="tableprocesslist" class="data clearfloat noclick sortable">'; $retval .= '<thead>'; @@ -498,7 +498,7 @@ function PMA_getTableProcesslistHtml($ServerStatusData) $retval .= '<tbody>'; $odd_row = true; - while ($process = PMA_DBI_fetchAssoc($result)) { + while ($process = $GLOBALS['dbi']->fetchAssoc($result)) { // Array keys need to modify due to the way it has used // to display column values diff --git a/server_variables.php b/server_variables.php index 136f358d8e..50356392ac 100644 --- a/server_variables.php +++ b/server_variables.php @@ -34,7 +34,7 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { if ($_REQUEST['type'] === 'getval') { // Send with correct charset header('Content-Type: text/html; charset=UTF-8'); - $varValue = PMA_DBI_fetchSingleRow( + $varValue = $GLOBALS['dbi']->fetchSingleRow( 'SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM' @@ -86,12 +86,12 @@ if (isset($_REQUEST['ajax_request']) && $_REQUEST['ajax_request'] == true) { } if (! preg_match("/[^a-zA-Z0-9_]+/", $_REQUEST['varName']) - && PMA_DBI_query( + && $GLOBALS['dbi']->query( 'SET GLOBAL ' . $_REQUEST['varName'] . ' = ' . $value ) ) { // Some values are rounded down etc. - $varValue = PMA_DBI_fetchSingleRow( + $varValue = $GLOBALS['dbi']->fetchSingleRow( 'SHOW GLOBAL VARIABLES WHERE Variable_name="' . PMA_Util::sqlAddSlashes($_REQUEST['varName']) . '";', 'NUM' @@ -144,8 +144,8 @@ $output .= PMA_Util::getImage( /** * Sends the queries and buffers the results */ -$serverVarsSession = PMA_DBI_fetchResult('SHOW SESSION VARIABLES;', 0, 1); -$serverVars = PMA_DBI_fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); +$serverVarsSession = $GLOBALS['dbi']->fetchResult('SHOW SESSION VARIABLES;', 0, 1); +$serverVars = $GLOBALS['dbi']->fetchResult('SHOW GLOBAL VARIABLES;', 0, 1); /** @@ -197,7 +197,7 @@ foreach ($serverVars as $name => $value) { $output .= htmlspecialchars(str_replace('_', ' ', $name)); } $output .= '</div>' - . '<div class="var-value value' . (PMA_isSuperuser() ? ' editable' : '') . '"> ' + . '<div class="var-value value' . ($GLOBALS['dbi']->isSuperuser() ? ' editable' : '') . '"> ' . PMA_formatVariable($name, $value) . '</div>' . '<div style="clear:both"></div>' @@ -515,7 +515,7 @@ if (($_SESSION['tmp_user_values']['max_rows'] != 'all') } if (strlen($db)) { - PMA_DBI_selectDb($db); + $GLOBALS['dbi']->selectDb($db); } // E x e c u t e t h e q u e r y @@ -527,22 +527,22 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { $unlim_num_rows = 0; } else { if (isset($_SESSION['profiling']) && PMA_Util::profilingSupported()) { - PMA_DBI_query('SET PROFILING=1;'); + $GLOBALS['dbi']->query('SET PROFILING=1;'); } // Measure query time. $querytime_before = array_sum(explode(' ', microtime())); - $result = @PMA_DBI_tryQuery($full_sql_query, null, PMA_DBI_QUERY_STORE); + $result = @$GLOBALS['dbi']->tryQuery($full_sql_query, null, PMA_DBI_QUERY_STORE); // If a stored procedure was called, there may be more results that are // queued up and waiting to be flushed from the buffer. So let's do that. do { - PMA_DBI_storeResult(); - if (! PMA_DBI_moreResults()) { + $GLOBALS['dbi']->storeResult(); + if (! $GLOBALS['dbi']->moreResults()) { break; } - } while (PMA_DBI_nextResult()); + } while ($GLOBALS['dbi']->nextResult()); $is_procedure = false; @@ -560,7 +560,7 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { $GLOBALS['querytime'] = $querytime_after - $querytime_before; // Displays an error message if required and stop parsing the script - $error = PMA_DBI_getError(); + $error = $GLOBALS['dbi']->getError(); if ($error) { if ($is_gotofile) { if (strpos($goto, 'db_') === 0 && strlen($table)) { @@ -623,14 +623,14 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { // mysql_affected_rows() reports about the last query done) if (! $is_affected) { - $num_rows = ($result) ? @PMA_DBI_numRows($result) : 0; + $num_rows = ($result) ? @$GLOBALS['dbi']->numRows($result) : 0; } elseif (! isset($num_rows)) { - $num_rows = @PMA_DBI_affectedRows(); + $num_rows = @$GLOBALS['dbi']->affectedRows(); } // Grabs the profiling results if (isset($_SESSION['profiling']) && PMA_Util::profilingSupported()) { - $profiling_results = PMA_DBI_fetchResult('SHOW PROFILE;'); + $profiling_results = $GLOBALS['dbi']->fetchResult('SHOW PROFILE;'); } // Checks if the current database has changed @@ -640,7 +640,7 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { * bug #2558 win: table list disappears (mixed case db names) * https://sourceforge.net/p/phpmyadmin/bugs/2558/ * @todo RELEASE test and comit or rollback before release - $current_db = PMA_DBI_fetchValue('SELECT DATABASE()'); + $current_db = $GLOBALS['dbi']->fetchValue('SELECT DATABASE()'); if ($db !== $current_db) { $db = $current_db; $reload = 1; @@ -726,7 +726,7 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { // run the count query - PMA_DBI_tryQuery($count_query); + $GLOBALS['dbi']->tryQuery($count_query); // if (mysql_error()) { // void. // I tried the case @@ -742,7 +742,7 @@ if (isset($GLOBALS['show_as_php']) || ! empty($GLOBALS['validatequery'])) { // SELECT COUNT(*), f1 from t1 group by f1 // and you click to sort on count(*) // } - $unlim_num_rows = PMA_DBI_fetchValue('SELECT FOUND_ROWS()'); + $unlim_num_rows = $GLOBALS['dbi']->fetchValue('SELECT FOUND_ROWS()'); } // end else "just browsing" } else { // not $is_select @@ -812,7 +812,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { } else { $message = PMA_Message::getMessageForInsertedRows($num_rows); } - $insert_id = PMA_DBI_insertId(); + $insert_id = $GLOBALS['dbi']->insertId(); if ($insert_id != 0) { // insert_id is id of FIRST record inserted in one insert, // so if we inserted multiple rows, we had to increment this @@ -933,7 +933,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { //If we are retrieving the full value of a truncated field or the original // value of a transformed field, show it here and exit if ($GLOBALS['grid_edit'] == true) { - $row = PMA_DBI_fetchRow($result); + $row = $GLOBALS['dbi']->fetchRow($result); $response = PMA_Response::getInstance(); $response->addJSON('value', $row[0]); exit; @@ -948,7 +948,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // Gets the list of fields properties if (isset($result) && $result) { - $fields_meta = PMA_DBI_getFieldsMeta($result); + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); $fields_cnt = count($fields_meta); } @@ -959,7 +959,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { } // hide edit and delete links for information_schema - if (PMA_isSystemSchema($db)) { + if ($GLOBALS['dbi']->isSystemSchema($db)) { $disp_mode = 'nnnn110111'; } @@ -1048,7 +1048,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { // Gets the list of fields properties if (isset($result) && $result) { - $fields_meta = PMA_DBI_getFieldsMeta($result); + $fields_meta = $GLOBALS['dbi']->getFieldsMeta($result); $fields_cnt = count($fields_meta); } @@ -1092,7 +1092,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { && trim($analyzed_sql[0]['select_expr_clause']) == '*' && PMA_Table::isUpdatableView($db, $table); $editable = $has_unique || $updatableView; - if (PMA_isSystemSchema($db) || ! $editable) { + if ($GLOBALS['dbi']->isSystemSchema($db) || ! $editable) { $disp_mode = 'nnnn110111'; $msg = PMA_message::notice( __( @@ -1135,7 +1135,7 @@ if ((0 == $num_rows && 0 == $unlim_num_rows) || $is_affected) { $html_output .= $displayResultsObject->getTable( $result, $disp_mode, $analyzed_sql ); - PMA_DBI_freeResult($result); + $GLOBALS['dbi']->freeResult($result); } // BEGIN INDEX CHECK See if indexes should be checked. diff --git a/tbl_addfield.php b/tbl_addfield.php index a3098429ae..499cb21ef0 100644 --- a/tbl_addfield.php +++ b/tbl_addfield.php @@ -57,13 +57,13 @@ if (isset($_REQUEST['do_save_data'])) { // To allow replication, we first select the db to use and then run queries // on this db. - PMA_DBI_selectDb($db) + $GLOBALS['dbi']->selectDb($db) or PMA_Util::mysqlDie( - PMA_DBI_getError(), 'USE ' . PMA_Util::backquote($db), '', $err_url + $GLOBALS['dbi']->getError(), 'USE ' . PMA_Util::backquote($db), '', $err_url ); $sql_query = 'ALTER TABLE ' . PMA_Util::backquote($table) . ' ' . $sql_statement . ';'; - $result = PMA_DBI_tryQuery($sql_query); + $result = $GLOBALS['dbi']->tryQuery($sql_query); if ($result === true) { // If comments were sent, enable relation stuff diff --git a/tbl_change.php b/tbl_change.php index a318316839..48fa95889b 100644 --- a/tbl_change.php +++ b/tbl_change.php @@ -137,8 +137,8 @@ $analyzed_sql = PMA_Table::analyzeStructure($db, $table); /** * Get the list of the fields of the current table */ -PMA_DBI_selectDb($db); -$table_fields = array_values(PMA_DBI_getColumns($db, $table)); +$GLOBALS['dbi']->selectDb($db); +$table_fields = array_values($GLOBALS['dbi']->getColumns($db, $table)); $paramTableDbArray = array($table, $db); @@ -286,7 +286,7 @@ foreach ($rows as $row_id => $current_row) { = PMA_Util::extractColumnSpec($column['Type']); if (-1 === $column['len']) { - $column['len'] = PMA_DBI_fieldLen($current_result, $i); + $column['len'] = $GLOBALS['dbi']->fieldLen($current_result, $i); // length is unknown for geometry fields, // make enough space to edit very simple WKTs if (-1 === $column['len']) { diff --git a/tbl_create.php b/tbl_create.php index da699ae6ef..ced10a6247 100644 --- a/tbl_create.php +++ b/tbl_create.php @@ -28,7 +28,7 @@ if (strlen($db) == 0) { /** * Defines the url to return to in case of error in a sql statement */ -if (PMA_DBI_getColumns($db, $table)) { +if ($GLOBALS['dbi']->getColumns($db, $table)) { // table exists already PMA_Util::mysqlDie( sprintf(__('Table %s already exists!'), htmlspecialchars($table)), @@ -53,7 +53,7 @@ if (isset($_REQUEST['submit_num_fields'])) { /** * Selects the database to work with */ -if (!PMA_DBI_selectDb($db)) { +if (!$GLOBALS['dbi']->selectDb($db)) { PMA_Util::mysqlDie( sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)), '', @@ -97,7 +97,7 @@ if (isset($_REQUEST['do_save_data'])) { $sql_query .= ';'; // Executes the query - $result = PMA_DBI_tryQuery($sql_query); + $result = $GLOBALS['dbi']->tryQuery($sql_query); if ($result) { @@ -141,12 +141,12 @@ if (isset($_REQUEST['do_save_data'])) { $tbl_url_params['table'] = $table; $is_show_stats = $cfg['ShowStats']; - $tbl_stats_result = PMA_DBI_query( + $tbl_stats_result = $GLOBALS['dbi']->query( 'SHOW TABLE STATUS FROM ' . PMA_Util::backquote($db) . ' LIKE \'' . PMA_Util::sqlAddSlashes($table, true) . '\';' ); - $tbl_stats = PMA_DBI_fetchAssoc($tbl_stats_result); - PMA_DBI_freeResult($tbl_stats_result); + $tbl_stats = $GLOBALS['dbi']->fetchAssoc($tbl_stats_result); + $GLOBALS['dbi']->freeResult($tbl_stats_result); unset($tbl_stats_result); if ($is_show_stats) { @@ -299,7 +299,7 @@ if (isset($_REQUEST['do_save_data'])) { if ($GLOBALS['is_ajax_request'] == true) { $response = PMA_Response::getInstance(); $response->isSuccess(false); - $response->addJSON('message', PMA_DBI_getError()); + $response->addJSON('message', $GLOBALS['dbi']->getError()); } else { echo PMA_Util::mysqlDie('', '', '', $err_url, false); // An error happened while inserting/updating a table definition. diff --git a/tbl_indexes.php b/tbl_indexes.php index 552314453b..94d337d819 100644 --- a/tbl_indexes.php +++ b/tbl_indexes.php @@ -15,7 +15,7 @@ require_once 'libraries/tbl_common.inc.php'; // Get fields and stores their name/type $fields = array(); -foreach (PMA_DBI_getColumnsFull($db, $table) as $row) { +foreach ($GLOBALS['dbi']->getColumnsFull($db, $table) as $row) { if (preg_match('@^(set|enum)\((.+)\)$@i', $row['Type'], $tmp)) { $tmp[2] = substr( preg_replace('@([^,])\'\'@', '\\1\\\'', ',' . $tmp[2]), 1 @@ -107,7 +107,7 @@ if (isset($_REQUEST['do_save_data'])) { $sql_query .= ';'; if (! $error) { - PMA_DBI_query($sql_query); + $GLOBALS['dbi']->query($sql_query); $message = PMA_Message::success( __('Table %1$s has been altered successfully') ); diff --git a/tbl_move_copy.php b/tbl_move_copy.php index 3c73ecfe27..403a4592b6 100644 --- a/tbl_move_copy.php +++ b/tbl_move_copy.php @@ -22,7 +22,7 @@ $err_url = 'tbl_sql.php?' . PMA_generate_common_url($db, $table); /** * Selects the database to work with */ -PMA_DBI_selectDb($db); +$GLOBALS['dbi']->selectDb($db); $goto = $cfg['DefaultTabTable']; diff --git a/tbl_operations.php b/tbl_operations.php index 1b1b8e7844..0aa403af62 100644 --- a/tbl_operations.php +++ b/tbl_operations.php @@ -43,7 +43,7 @@ require_once 'libraries/Partition.class.php'; // reselect current db (needed in some cases probably due to // the calling of relation.lib.php) -PMA_DBI_selectDb($GLOBALS['db']); +$GLOBALS['dbi']->selectDb($GLOBALS['db']); /** * Gets tables informations @@ -143,7 +143,7 @@ if (isset($_REQUEST['submitoptions'])) { . PMA_Util::backquote($GLOBALS['table']); $sql_query .= "\r\n" . implode("\r\n", $table_alters); $sql_query .= ';'; - $result .= PMA_DBI_query($sql_query) ? true : false; + $result .= $GLOBALS['dbi']->query($sql_query) ? true : false; $reread_info = true; unset($table_alters); $warning_messages = PMA_getWarningMessagesArray(); @@ -225,7 +225,7 @@ $url_params['goto'] /** * Get columns names */ -$columns = PMA_DBI_getColumns($GLOBALS['db'], $GLOBALS['table']); +$columns = $GLOBALS['dbi']->getColumns($GLOBALS['db'], $GLOBALS['table']); /** * Displays the page @@ -363,7 +363,7 @@ unset($partition_names); // this choice (InnoDB maintains integrity by itself) if ($cfgRelation['relwork'] && ! $is_innodb) { - PMA_DBI_selectDb($GLOBALS['db']); + $GLOBALS['dbi']->selectDb($GLOBALS['db']); $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']); if ($foreign) { diff --git a/tbl_printview.php b/tbl_printview.php index e798f8c510..ceba50268a 100644 --- a/tbl_printview.php +++ b/tbl_printview.php @@ -43,7 +43,7 @@ if (strlen($table)) { /** * Selects the database */ -PMA_DBI_selectDb($db); +$GLOBALS['dbi']->selectDb($db); /** @@ -92,7 +92,7 @@ foreach ($the_tables as $key => $table) { /** * Gets fields properties */ - $columns = PMA_DBI_getColumns($db, $table); + $columns = $GLOBALS['dbi']->getColumns($db, $table); // We need this to correctly learn if a TIMESTAMP is NOT NULL, since @@ -100,7 +100,7 @@ foreach ($the_tables as $key => $table) { // and SHOW CREATE TABLE says NOT NULL (tested // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910). - $show_create_table = PMA_DBI_fetchValue( + $show_create_table = $GLOBALS['dbi']->fetchValue( 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1 @@ -160,7 +160,7 @@ foreach ($the_tables as $key => $table) { // the latter. /** * @todo merge this logic with the one in tbl_structure.php - * or move it in a function similar to PMA_DBI_getColumnsFull() + * or move it in a function similar to $GLOBALS['dbi']->getColumnsFull() * but based on SHOW CREATE TABLE because information_schema * cannot be trusted in this case (MySQL bug) */ @@ -222,7 +222,7 @@ foreach ($the_tables as $key => $table) { } // end foreach echo '</tbody>'; echo '</table>'; - if (! $tbl_is_view && !PMA_isSystemSchema($db)) { + if (! $tbl_is_view && !$GLOBALS['dbi']->isSystemSchema($db)) { /** * Displays indexes */ diff --git a/tbl_relation.php b/tbl_relation.php index cd3422c5e1..e102ca3f47 100644 --- a/tbl_relation.php +++ b/tbl_relation.php @@ -182,8 +182,8 @@ if (isset($_REQUEST['destination_foreign'])) { $table, $existrel_foreign[$master_field]['constraint'] ); $display_query .= $drop_query . "\n"; - PMA_DBI_tryQuery($drop_query); - $tmp_error_drop = PMA_DBI_getError(); + $GLOBALS['dbi']->tryQuery($drop_query); + $tmp_error_drop = $GLOBALS['dbi']->getError(); if (! empty($tmp_error_drop)) { $seen_error = true; @@ -203,8 +203,8 @@ if (isset($_REQUEST['destination_foreign'])) { ); $display_query .= $create_query . "\n"; - PMA_DBI_tryQuery($create_query); - $tmp_error_create = PMA_DBI_getError(); + $GLOBALS['dbi']->tryQuery($create_query); + $tmp_error_create = $GLOBALS['dbi']->getError(); if (! empty($tmp_error_create)) { $seen_error = true; @@ -241,7 +241,7 @@ if (isset($_REQUEST['destination_foreign'])) { $options_array[$existrel_foreign[$master_field]['on_update']] ); $display_query .= $sql_query_recreate . "\n"; - PMA_DBI_tryQuery($sql_query_recreate); + $GLOBALS['dbi']->tryQuery($sql_query_recreate); } } } // end foreach @@ -332,11 +332,11 @@ if ($cfgRelation['relwork'] // [0] of the row is the name } - $tab_rs = PMA_DBI_query($tab_query, null, PMA_DBI_QUERY_STORE); + $tab_rs = $GLOBALS['dbi']->query($tab_query, null, PMA_DBI_QUERY_STORE); $selectboxall[] = ''; $selectboxall_foreign[] = ''; - while ($curr_table = PMA_DBI_fetchRow($tab_rs)) { + while ($curr_table = $GLOBALS['dbi']->fetchRow($tab_rs)) { $current_table = new PMA_Table($curr_table[0], $db); // explicitely ask for non-quoted list of indexed columns @@ -362,8 +362,8 @@ if ($cfgRelation['relwork'] } // end if // Now find out the columns of our $table -// need to use PMA_DBI_QUERY_STORE with PMA_DBI_numRows() in mysqli -$columns = PMA_DBI_getColumns($db, $table); +// need to use PMA_DBI_QUERY_STORE with $GLOBALS['dbi']->numRows() in mysqli +$columns = $GLOBALS['dbi']->getColumns($db, $table); if (count($columns) > 0) { diff --git a/tbl_replace.php b/tbl_replace.php index 646605d614..929919891f 100644 --- a/tbl_replace.php +++ b/tbl_replace.php @@ -25,7 +25,7 @@ require_once 'libraries/insert_edit.lib.php'; // Check parameters PMA_Util::checkParameters(array('db', 'table', 'goto')); -PMA_DBI_selectDb($GLOBALS['db']); +$GLOBALS['dbi']->selectDb($GLOBALS['db']); /** * Initializes some variables diff --git a/tbl_structure.php b/tbl_structure.php index bdb58e9e44..8e2bc61cfa 100644 --- a/tbl_structure.php +++ b/tbl_structure.php @@ -162,7 +162,7 @@ $primary = PMA_Index::getPrimary($table, $db); $columns_with_unique_index = PMA_getColumnsWithUniqueIndex($db, $table); // 3. Get fields -$fields = (array) PMA_DBI_getColumns($db, $table, null, true); +$fields = (array) $GLOBALS['dbi']->getColumns($db, $table, null, true); // Get more complete field information // For now, this is done just for MySQL 4.1.2+ new TIMESTAMP options @@ -175,7 +175,7 @@ $fields = (array) PMA_DBI_getColumns($db, $table, null, true); // and SHOW CREATE TABLE says NOT NULL (tested // in MySQL 4.0.25 and 5.0.21, http://bugs.mysql.com/20910). -$show_create_table = PMA_DBI_fetchValue( +$show_create_table = $GLOBALS['dbi']->fetchValue( 'SHOW CREATE TABLE ' . PMA_Util::backquote($db) . '.' . PMA_Util::backquote($table), 0, 1 diff --git a/tbl_tracking.php b/tbl_tracking.php index a2e8ae8844..3e71694f84 100644 --- a/tbl_tracking.php +++ b/tbl_tracking.php @@ -248,7 +248,7 @@ if (isset($_REQUEST['submit_activate_now'])) { // Export as SQL execution if (isset($_REQUEST['report_export']) && $_REQUEST['export_type'] == 'execution') { foreach ($entries as $entry) { - $sql_result = PMA_DBI_query("/*NOTRACK*/\n" . $entry['statement']); + $sql_result = $GLOBALS['dbi']->query("/*NOTRACK*/\n" . $entry['statement']); } $msg = PMA_Message::success(__('SQL statements executed.')); $msg->display(); @@ -715,10 +715,10 @@ $sql_query = " SELECT DISTINCT db_name, table_name FROM " . $sql_result = PMA_queryAsControlUser($sql_query); -if (PMA_DBI_numRows($sql_result) > 0) { +if ($GLOBALS['dbi']->numRows($sql_result) > 0) { echo '<form method="post" action="tbl_tracking.php?' . $url_query . '">'; echo '<select name="table">'; - while ($entries = PMA_DBI_fetchArray($sql_result)) { + while ($entries = $GLOBALS['dbi']->fetchArray($sql_result)) { if (PMA_Tracker::isTracked($entries['db_name'], $entries['table_name'])) { $status = ' (' . __('active') . ')'; } else { @@ -752,7 +752,7 @@ $sql_query = " SELECT * FROM " . $sql_result = PMA_queryAsControlUser($sql_query); $last_version = 0; -$maxversion = PMA_DBI_fetchArray($sql_result); +$maxversion = $GLOBALS['dbi']->fetchArray($sql_result); $last_version = $maxversion['version']; if ($last_version > 0) { @@ -771,8 +771,8 @@ if ($last_version > 0) { echo '<tbody>'; $style = 'odd'; - PMA_DBI_dataSeek($sql_result, 0); - while ($version = PMA_DBI_fetchArray($sql_result)) { + $GLOBALS['dbi']->dataSeek($sql_result, 0); + while ($version = $GLOBALS['dbi']->fetchArray($sql_result)) { if ($version['tracking_active'] == 1) { $version_status = __('active'); } else { diff --git a/test/classes/PMA_DBQbe_test.php b/test/classes/PMA_DBQbe_test.php index 187696822c..269bfe3622 100644 --- a/test/classes/PMA_DBQbe_test.php +++ b/test/classes/PMA_DBQbe_test.php @@ -13,7 +13,7 @@ require_once 'libraries/DBQbe.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Util.class.php'; require_once 'libraries/core.lib.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/relation.lib.php'; diff --git a/test/classes/PMA_DbSearch_test.php b/test/classes/PMA_DbSearch_test.php index dfa4239751..36e25915f1 100644 --- a/test/classes/PMA_DbSearch_test.php +++ b/test/classes/PMA_DbSearch_test.php @@ -15,7 +15,7 @@ require_once 'libraries/Util.class.php'; require_once 'libraries/url_generating.lib.php'; require_once 'libraries/core.lib.php'; require_once 'libraries/Theme.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; /** diff --git a/test/classes/PMA_Header_test.php b/test/classes/PMA_Header_test.php index a174e10337..9149af08da 100644 --- a/test/classes/PMA_Header_test.php +++ b/test/classes/PMA_Header_test.php @@ -13,7 +13,7 @@ require_once 'libraries/sanitizing.lib.php'; require_once 'libraries/core.lib.php'; require_once 'libraries/Header.class.php'; require_once 'libraries/Table.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/Util.class.php'; require_once 'libraries/Config.class.php'; diff --git a/test/classes/PMA_Menu_test.php b/test/classes/PMA_Menu_test.php index 3183ab5cbb..ef07768ec3 100644 --- a/test/classes/PMA_Menu_test.php +++ b/test/classes/PMA_Menu_test.php @@ -13,7 +13,7 @@ require_once 'libraries/sanitizing.lib.php'; require_once 'libraries/core.lib.php'; require_once 'libraries/Menu.class.php'; require_once 'libraries/Table.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/Util.class.php'; require_once 'libraries/Theme.class.php'; diff --git a/test/classes/PMA_StorageEngine_test.php b/test/classes/PMA_StorageEngine_test.php index 1f57ebd35b..dff0f8deb5 100644 --- a/test/classes/PMA_StorageEngine_test.php +++ b/test/classes/PMA_StorageEngine_test.php @@ -12,7 +12,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Util.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; /** diff --git a/test/classes/PMA_Table_test.php b/test/classes/PMA_Table_test.php index 5bf6553a45..7383574ded 100644 --- a/test/classes/PMA_Table_test.php +++ b/test/classes/PMA_Table_test.php @@ -11,7 +11,7 @@ require_once 'libraries/Table.class.php'; require_once 'libraries/Util.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/url_generating.lib.php'; require_once 'libraries/Theme.class.php'; diff --git a/test/classes/PMA_Types_Drizzle_test.php b/test/classes/PMA_Types_Drizzle_test.php index c166bc8092..71ebe15cb1 100644 --- a/test/classes/PMA_Types_Drizzle_test.php +++ b/test/classes/PMA_Types_Drizzle_test.php @@ -11,7 +11,7 @@ require_once 'libraries/Types.class.php'; require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_Types_Drizzle_Test extends PHPUnit_Framework_TestCase diff --git a/test/classes/navigation/PMA_Node_test.php b/test/classes/navigation/PMA_Node_test.php index 0b6fb3b348..b32a586140 100644 --- a/test/classes/navigation/PMA_Node_test.php +++ b/test/classes/navigation/PMA_Node_test.php @@ -9,7 +9,7 @@ require_once 'libraries/navigation/NodeFactory.class.php'; require_once 'libraries/Util.class.php'; require_once 'libraries/Theme.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; class Node_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_bdb_test.php b/test/engines/PMA_StorageEngine_bdb_test.php index 63344b5221..41d5f151fb 100644 --- a/test/engines/PMA_StorageEngine_bdb_test.php +++ b/test/engines/PMA_StorageEngine_bdb_test.php @@ -12,7 +12,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/bdb.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_bdb_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_binlog_test.php b/test/engines/PMA_StorageEngine_binlog_test.php index 6af4572b94..ba2daaf711 100644 --- a/test/engines/PMA_StorageEngine_binlog_test.php +++ b/test/engines/PMA_StorageEngine_binlog_test.php @@ -11,7 +11,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/binlog.lib.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_binlog_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_innodb_test.php b/test/engines/PMA_StorageEngine_innodb_test.php index 5983a99ad2..91b6bc0de0 100644 --- a/test/engines/PMA_StorageEngine_innodb_test.php +++ b/test/engines/PMA_StorageEngine_innodb_test.php @@ -13,7 +13,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/innodb.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Util.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_innodb_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_memory_test.php b/test/engines/PMA_StorageEngine_memory_test.php index e0e439265c..b9789e606d 100644 --- a/test/engines/PMA_StorageEngine_memory_test.php +++ b/test/engines/PMA_StorageEngine_memory_test.php @@ -12,7 +12,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/memory.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_memory_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_mrg_myisam_test.php b/test/engines/PMA_StorageEngine_mrg_myisam_test.php index 0b90b525eb..639797fec9 100644 --- a/test/engines/PMA_StorageEngine_mrg_myisam_test.php +++ b/test/engines/PMA_StorageEngine_mrg_myisam_test.php @@ -11,7 +11,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/mrg_myisam.lib.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_mrg_myisam_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_myisam_test.php b/test/engines/PMA_StorageEngine_myisam_test.php index 0f8b518059..f397e330b9 100644 --- a/test/engines/PMA_StorageEngine_myisam_test.php +++ b/test/engines/PMA_StorageEngine_myisam_test.php @@ -12,7 +12,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/myisam.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_myisam_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_ndbcluster_test.php b/test/engines/PMA_StorageEngine_ndbcluster_test.php index a883911c84..e88d5590c4 100644 --- a/test/engines/PMA_StorageEngine_ndbcluster_test.php +++ b/test/engines/PMA_StorageEngine_ndbcluster_test.php @@ -12,7 +12,7 @@ require_once 'libraries/StorageEngine.class.php'; require_once 'libraries/engines/ndbcluster.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_ndbcluster_Test extends PHPUnit_Framework_TestCase diff --git a/test/engines/PMA_StorageEngine_pbxt_test.php b/test/engines/PMA_StorageEngine_pbxt_test.php index f98ff5eba4..fa81c3fbe3 100644 --- a/test/engines/PMA_StorageEngine_pbxt_test.php +++ b/test/engines/PMA_StorageEngine_pbxt_test.php @@ -14,7 +14,7 @@ require_once 'libraries/engines/pbxt.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/Util.class.php'; require_once 'libraries/core.lib.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; class PMA_StorageEngine_pbxt_Test extends PHPUnit_Framework_TestCase diff --git a/test/libraries/PMA_bookmark_test.php b/test/libraries/PMA_bookmark_test.php index 9ebc01ef6d..85d04a3125 100644 --- a/test/libraries/PMA_bookmark_test.php +++ b/test/libraries/PMA_bookmark_test.php @@ -11,7 +11,7 @@ */ require_once 'libraries/Util.class.php'; require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/relation.lib.php'; diff --git a/test/libraries/PMA_build_html_for_db_test.php b/test/libraries/PMA_build_html_for_db_test.php index 965c28aa83..3b6b56b4c5 100644 --- a/test/libraries/PMA_build_html_for_db_test.php +++ b/test/libraries/PMA_build_html_for_db_test.php @@ -16,7 +16,7 @@ require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/build_html_for_db.lib.php'; require_once 'libraries/js_escape.lib.php'; require_once 'libraries/Theme.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/Types.class.php'; require_once 'libraries/mysql_charsets.lib.php'; diff --git a/test/libraries/PMA_operations_test.php b/test/libraries/PMA_operations_test.php index 5701257f19..970c53b382 100644 --- a/test/libraries/PMA_operations_test.php +++ b/test/libraries/PMA_operations_test.php @@ -17,7 +17,7 @@ require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/relation.lib.php'; require_once 'libraries/Util.class.php'; require_once 'libraries/Theme.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/mysql_charsets.lib.php'; diff --git a/test/libraries/PMA_transformation_test.php b/test/libraries/PMA_transformation_test.php index 44bb1c8fde..8a319dc803 100644 --- a/test/libraries/PMA_transformation_test.php +++ b/test/libraries/PMA_transformation_test.php @@ -11,7 +11,7 @@ */ require_once 'libraries/transformations.lib.php'; require_once 'libraries/Util.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/relation.lib.php'; require_once 'libraries/Theme.class.php'; diff --git a/test/libraries/core/PMA_getTableCount_test_dis.php b/test/libraries/core/PMA_getTableCount_test_dis.php index 90cddc68c0..4a445f21ac 100644 --- a/test/libraries/core/PMA_getTableCount_test_dis.php +++ b/test/libraries/core/PMA_getTableCount_test_dis.php @@ -25,7 +25,7 @@ require_once 'libraries/Config.class.php'; require_once 'libraries/url_generating.lib.php'; require_once 'libraries/Table.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'config.sample.inc.php'; diff --git a/test/libraries/database_interface_test.php b/test/libraries/database_interface_test.php index 34aa83d973..838fdb140b 100644 --- a/test/libraries/database_interface_test.php +++ b/test/libraries/database_interface_test.php @@ -10,7 +10,7 @@ * Include to test. */ require_once 'libraries/php-gettext/gettext.inc'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; /** @@ -39,7 +39,7 @@ class PMA_DBI_Test extends PHPUnit_Framework_TestCase */ function testQuery() { - $this->assertEquals(0, PMA_DBI_tryQuery('SELECT 1')); + $this->assertEquals(0, $GLOBALS['dbi']->tryQuery('SELECT 1')); } /** @@ -51,7 +51,7 @@ class PMA_DBI_Test extends PHPUnit_Framework_TestCase */ function testFetch() { - $this->assertEquals(array('1'), PMA_DBI_fetchArray(0)); + $this->assertEquals(array('1'), $GLOBALS['dbi']->fetchArray(0)); } /** @@ -66,7 +66,7 @@ class PMA_DBI_Test extends PHPUnit_Framework_TestCase */ function testSystemSchema($schema, $expected) { - $this->assertEquals($expected, PMA_isSystemSchema($schema)); + $this->assertEquals($expected, $GLOBALS['dbi']->isSystemSchema($schema)); } /** @@ -97,7 +97,7 @@ class PMA_DBI_Test extends PHPUnit_Framework_TestCase { $this->assertEquals( $expected, - PMA_DBI_formatError($number, $message) + $GLOBALS['dbi']->formatError($number, $message) ); } diff --git a/test/libraries/rte/PMA_RTN_getEditorForm_test.php b/test/libraries/rte/PMA_RTN_getEditorForm_test.php index 8c8fab0e06..6160555bb2 100644 --- a/test/libraries/rte/PMA_RTN_getEditorForm_test.php +++ b/test/libraries/rte/PMA_RTN_getEditorForm_test.php @@ -11,7 +11,7 @@ require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/url_generating.lib.php'; require_once './libraries/Types.class.php'; require_once 'libraries/Theme.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; require_once 'libraries/mysql_charsets.lib.php'; /* diff --git a/test/libraries/rte/PMA_RTN_getExecuteForm_test.php b/test/libraries/rte/PMA_RTN_getExecuteForm_test.php index 755dd7804f..f0c4f2044f 100644 --- a/test/libraries/rte/PMA_RTN_getExecuteForm_test.php +++ b/test/libraries/rte/PMA_RTN_getExecuteForm_test.php @@ -11,7 +11,7 @@ require_once 'libraries/sqlparser.lib.php'; require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/url_generating.lib.php'; require_once './libraries/Types.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; /* * Include to test. diff --git a/test/libraries/rte/PMA_TRI_getEditorForm_test.php b/test/libraries/rte/PMA_TRI_getEditorForm_test.php index 6fca3ef8c1..4a44b337d7 100644 --- a/test/libraries/rte/PMA_TRI_getEditorForm_test.php +++ b/test/libraries/rte/PMA_TRI_getEditorForm_test.php @@ -8,7 +8,7 @@ require_once 'libraries/php-gettext/gettext.inc'; require_once 'libraries/url_generating.lib.php'; require_once 'libraries/Util.class.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; /* * Include to test. diff --git a/test/libraries/rte/PMA_TRI_getQueryFromRequest_test.php b/test/libraries/rte/PMA_TRI_getQueryFromRequest_test.php index 23c6191836..cf22832d60 100644 --- a/test/libraries/rte/PMA_TRI_getQueryFromRequest_test.php +++ b/test/libraries/rte/PMA_TRI_getQueryFromRequest_test.php @@ -20,7 +20,7 @@ require_once 'libraries/php-gettext/gettext.inc'; * Include to test. */ require_once 'libraries/rte/rte_triggers.lib.php'; -require_once 'libraries/database_interface.lib.php'; +require_once 'libraries/DatabaseInterface.class.php'; require_once 'libraries/Tracker.class.php'; diff --git a/transformation_wrapper.php b/transformation_wrapper.php index 2c55f84c4a..d9f3ef92fe 100644 --- a/transformation_wrapper.php +++ b/transformation_wrapper.php @@ -46,21 +46,21 @@ foreach ($request_params as $one_request_param) { /** * Get the list of the fields of the current table */ -PMA_DBI_selectDb($db); +$GLOBALS['dbi']->selectDb($db); if (isset($where_clause)) { - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SELECT * FROM ' . PMA_Util::backquote($table) . ' WHERE ' . $where_clause . ';', null, PMA_DBI_QUERY_STORE ); - $row = PMA_DBI_fetchAssoc($result); + $row = $GLOBALS['dbi']->fetchAssoc($result); } else { - $result = PMA_DBI_query( + $result = $GLOBALS['dbi']->query( 'SELECT * FROM ' . PMA_Util::backquote($table) . ' LIMIT 1;', null, PMA_DBI_QUERY_STORE ); - $row = PMA_DBI_fetchAssoc($result); + $row = $GLOBALS['dbi']->fetchAssoc($result); } // No row returned diff --git a/user_password.php b/user_password.php index ca105612de..252302bda8 100644 --- a/user_password.php +++ b/user_password.php @@ -22,7 +22,7 @@ $scripts->addFile('server_privileges.js'); * script */ if (! $cfg['ShowChgPassword']) { - $cfg['ShowChgPassword'] = PMA_DBI_selectDb('mysql'); + $cfg['ShowChgPassword'] = $GLOBALS['dbi']->selectDb('mysql'); } if ($cfg['Server']['auth_type'] == 'config' || ! $cfg['ShowChgPassword']) { PMA_Message::error( @@ -174,8 +174,8 @@ function PMA_ChangePassUrlParamsAndSubmitQuery( $local_query = 'SET password = ' . (($password == '') ? '\'\'' : $hashing_function . '(\'' . PMA_Util::sqlAddSlashes($password) . '\')'); - if (! @PMA_DBI_tryQuery($local_query)) { - PMA_Util::mysqlDie(PMA_DBI_getError(), $sql_query, false, $err_url); + if (! @$GLOBALS['dbi']->tryQuery($local_query)) { + PMA_Util::mysqlDie($GLOBALS['dbi']->getError(), $sql_query, false, $err_url); } } diff --git a/view_create.php b/view_create.php index 7178987ccb..9c6ccd361d 100644 --- a/view_create.php +++ b/view_create.php @@ -62,7 +62,7 @@ if (isset($_REQUEST['createview'])) { } } - if (PMA_DBI_tryQuery($sql_query)) { + if ($GLOBALS['dbi']->tryQuery($sql_query)) { include_once './libraries/tbl_views.lib.php'; @@ -85,7 +85,7 @@ if (isset($_REQUEST['createview'])) { // Store new transformations if ($new_transformations_sql != '') { - PMA_DBI_tryQuery($new_transformations_sql); + $GLOBALS['dbi']->tryQuery($new_transformations_sql); } } @@ -108,13 +108,13 @@ if (isset($_REQUEST['createview'])) { } else { if ($GLOBALS['is_ajax_request'] != true) { - $message = PMA_Message::rawError(PMA_DBI_getError()); + $message = PMA_Message::rawError($GLOBALS['dbi']->getError()); } else { $response = PMA_Response::getInstance(); $response->addJSON( 'message', PMA_Message::error( - "<i>$sql_query</i><br /><br />" . PMA_DBI_getError() + "<i>$sql_query</i><br /><br />" . $GLOBALS['dbi']->getError() ) ); $response->isSuccess(false); |