📄 common.lib.php
字号:
$tmp_mysql_error = ''; // for saving the original $error_message if (!empty($error_message)) { $tmp_mysql_error = strtolower($error_message); // save the original $error_message $error_message = htmlspecialchars($error_message); $error_message = preg_replace("@((\015\012)|(\015)|(\012)){3,}@", "\n\n", $error_message); } // modified to show me the help on error-returns (Michael Keck) echo '<p>' . "\n" . ' <strong>' . $GLOBALS['strMySQLSaid'] . '</strong>' . PMA_showMySQLDocu('Error-returns', 'Error-returns') . "\n" . '</p>' . "\n"; // The error message will be displayed within a CODE segment. // To preserve original formatting, but allow wordwrapping, we do a couple of replacements // Replace all non-single blanks with their HTML-counterpart $error_message = str_replace(' ', ' ', $error_message); // Replace TAB-characters with their HTML-counterpart $error_message = str_replace("\t", ' ', $error_message); // Replace linebreaks $error_message = nl2br($error_message); echo '<code>' . "\n" . $error_message . "\n" . '</code><br />' . "\n"; // feature request #1036254: // Add a link by MySQL-Error #1062 - Duplicate entry // 2004-10-20 by mkkeck // 2005-01-17 modified by mkkeck bugfix if (substr($error_message, 1, 4) == '1062') { // get the duplicate entry // get table name preg_match( '癆LTER\sTABLE\s\`([^\`]+)\`癷u', $the_query, $error_table = array() ); $error_table = $error_table[1]; // get fields preg_match( '癨(([^\)]+)\)癷', $the_query, $error_fields = array() ); $error_fields = explode( ',', $error_fields[1] ); // duplicate value preg_match( '癨'([^\']+)\'癷', $tmp_mysql_error, $duplicate_value = array() ); $duplicate_value = $duplicate_value[1]; $sql = ' SELECT * FROM ' . PMA_backquote( $error_table ) . ' WHERE CONCAT_WS( "-", ' . implode( ', ', $error_fields ) . ' ) = "' . PMA_sqlAddslashes( $duplicate_value ) . '" ORDER BY ' . implode( ', ', $error_fields ); unset( $error_table, $error_fields, $duplicate_value ); echo ' <form method="post" action="import.php" style="padding: 0; margin: 0">' ."\n" .' <input type="hidden" name="sql_query" value="' . htmlentities( $sql ) . '" />' . "\n" .' ' . PMA_generate_common_hidden_inputs($db, $table) . "\n" .' <input type="submit" name="submit" value="' . $GLOBALS['strBrowse'] . '" />' . "\n" .' </form>' . "\n"; unset( $sql ); } // end of show duplicate entry echo '</div>'; echo '<fieldset class="tblFooters">'; if (!empty($back_url) && $exit) { $goto_back_url='<a href="' . (strstr($back_url, '?') ? $back_url . '&no_history=true' : $back_url . '?no_history=true') . '">'; echo '[ ' . $goto_back_url . $GLOBALS['strBack'] . '</a> ]'; } echo ' </fieldset>' . "\n\n"; if ($exit) { require_once('./footer.inc.php'); } } // end of the 'PMA_mysqlDie()' function /** * Defines whether a string exists inside an array or not * * @param string string to search for * @param mixed array to search into * * @return integer the rank of the $toFind string in the array or '-1' if * it hasn't been found * * @access public */ function PMA_isInto($toFind = '', &$in) { $max = count($in); for ($i = 0; $i < $max && ($toFind != $in[$i]); $i++) { // void(); } return ($i < $max) ? $i : -1; } // end of the 'PMA_isInto()' function /** * Returns a string formatted with CONVERT ... USING * if MySQL supports it * * @param string the string itself * @param string the mode: quoted or unquoted (this one by default) * * @return the formatted string * * @access private */ function PMA_convert_using($string, $mode='unquoted') { if ($mode == 'quoted') { $possible_quote = "'"; } else { $possible_quote = ""; } if (PMA_MYSQL_INT_VERSION >= 40100) { list($conn_charset) = explode('_', $GLOBALS['collation_connection']); $converted_string = "CONVERT(" . $possible_quote . $string . $possible_quote . " USING " . $conn_charset . ")"; } else { $converted_string = $possible_quote . $string . $possible_quote; } return $converted_string; } // end function}/** * returns array with dbs grouped with extended infos * * @uses $GLOBALS['dblist'] from PMA_availableDatabases() * @uses $GLOBALS['num_dbs'] from PMA_availableDatabases() * @uses $GLOBALS['cfgRelation']['commwork'] * @uses $GLOBALS['cfg']['ShowTooltip'] * @uses $GLOBALS['cfg']['LeftFrameDBTree'] * @uses $GLOBALS['cfg']['LeftFrameDBSeparator'] * @uses $GLOBALS['cfg']['ShowTooltipAliasDB'] * @uses PMA_availableDatabases() * @uses PMA_getTableCount() * @uses PMA_getComments() * @uses PMA_availableDatabases() * @uses is_array() * @uses implode() * @uses strstr() * @uses explode() * @return array db list */function PMA_getDbList() { if ( empty( $GLOBALS['dblist'] ) ) { PMA_availableDatabases(); } $dblist = $GLOBALS['dblist']; $dbgroups = array(); $parts = array(); foreach ( $dblist as $key => $db ) { // garvin: Get comments from PMA comments table $db_tooltip = ''; if ( $GLOBALS['cfg']['ShowTooltip'] && $GLOBALS['cfgRelation']['commwork'] ) { $_db_tooltip = PMA_getComments( $db ); if ( is_array( $_db_tooltip ) ) { $db_tooltip = implode( ' ', $_db_tooltip ); } } if ( $GLOBALS['cfg']['LeftFrameDBTree'] && $GLOBALS['cfg']['LeftFrameDBSeparator'] && strstr( $db, $GLOBALS['cfg']['LeftFrameDBSeparator'] ) ) { $pos = strrpos($db, $GLOBALS['cfg']['LeftFrameDBSeparator']); $group = substr($db, 0, $pos); $disp_name_cut = substr($db, $pos); } else { $group = $db; $disp_name_cut = $db; } $disp_name = $db; if ( $db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB'] ) { $disp_name = $db_tooltip; $disp_name_cut = $db_tooltip; $db_tooltip = $db; } $dbgroups[$group][$db] = array( 'name' => $db, 'disp_name_cut' => $disp_name_cut, 'disp_name' => $disp_name, 'comment' => $db_tooltip, 'num_tables' => PMA_getTableCount( $db ), ); } // end foreach ( $dblist as $db ) return $dbgroups;}/** * returns html code for select form element with dbs * * @return string html code select */function PMA_getHtmlSelectDb( $selected = '' ) { $dblist = PMA_getDbList(); // TODO: IE can not handle different text directions in select boxes // so, as mostly names will be in english, we set the whole selectbox to LTR // and EN $return = '<select name="db" id="lightm_db" xml:lang="en" dir="ltr"' .' onchange="window.parent.openDb( this.value );">' . "\n" .'<option value="" dir="' . $GLOBALS['text_dir'] . '">(' . $GLOBALS['strDatabases'] . ') ...</option>' ."\n"; foreach( $dblist as $group => $dbs ) { if ( count( $dbs ) > 1 ) { $return .= '<optgroup label="' . htmlspecialchars( $group ) . '">' . "\n"; // wether display db_name cuted by the group part $cut = true; } else { // .. or full $cut = false; } foreach( $dbs as $db ) { $return .= '<option value="' . $db['name'] . '"' .' title="' . $db['comment'] . '"'; if ( $db['name'] == $selected ) { $return .= ' selected="selected"'; } $return .= '>' . ( $cut ? $db['disp_name_cut'] : $db['disp_name'] ) .' (' . $db['num_tables'] . ')</option>' . "\n"; } if ( count( $dbs ) > 1 ) { $return .= '</optgroup>' . "\n"; } } $return .= '</select>'; return $return;}/** * returns count of tables in given db * * @param string $db database to count tables for * @return integer count of tables in $db */function PMA_getTableCount( $db ) { $tables = PMA_DBI_try_query( 'SHOW TABLES FROM ' . PMA_backquote( $db ) . ';', NULL, PMA_DBI_QUERY_STORE); if ( $tables ) { $num_tables = PMA_DBI_num_rows( $tables ); PMA_DBI_free_result( $tables ); } else { $num_tables = 0; } return $num_tables;}/** * Get the complete list of Databases a user can access * * @param boolean whether to include check on failed 'only_db' operations * @param resource database handle (superuser) * @param integer amount of databases inside the 'only_db' container * @param resource possible resource from a failed previous query * @param resource database handle (user) * @param array configuration * @param array previous list of databases * * @return array all databases a user has access to * * @access private */function PMA_safe_db_list($only_db_check, $dbh, $dblist_cnt, $rs, $userlink, $cfg, $dblist) { if ($only_db_check == FALSE) { // try to get the available dbs list // use userlink by default $dblist = PMA_DBI_get_dblist(); $dblist_cnt = count($dblist); // did not work so check for available databases in the "mysql" db; // I don't think we can fall here now... if (!$dblist_cnt) { $auth_query = 'SELECT User, Select_priv ' . 'FROM mysql.user ' . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\''; $rs = PMA_DBI_try_query($auth_query, $dbh); } // end } // Access to "mysql" db allowed and dblist still empty -> gets the // usable db list if (!$dblist_cnt && ($rs && @PMA_DBI_num_rows($rs))) { $row = PMA_DBI_fetch_assoc($rs); PMA_DBI_free_result($rs); // Correction uva 19991215 // Previous code assumed database "mysql" admin table "db" column // "db" contains literal name of user database, and works if so. // Mysql usage generally (and uva usage specifically) allows this // column to contain regular expressions (we have all databases // owned by a given student/faculty/staff beginning with user i.d. // and governed by default by a single set of privileges with // regular expression as key). This breaks previous code. // This maintenance is to fix code to work correctly for regular // expressions. if ($row['Select_priv'] != 'Y') { // 1. get allowed dbs from the "mysql.db" table // lem9: User can be blank (anonymous user) $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')'; $rs = PMA_DBI_try_query($local_query, $dbh); if ($rs && @PMA_DBI_num_rows($rs)) { // Will use as associative array of the following 2 code // lines: // the 1st is the only line intact from before // correction, // the 2nd replaces $dblist[] = $row['Db']; $uva_mydbs = array(); // Code following those 2 lines in correction continues // populating $dblist[], as previous code did. But it is // now populated with actual database names instead of // with regular expressions. while ($row = PMA_DBI_fetch_assoc($rs)) { // loic1: all databases cases - part 1 if (empty($row['Db']) || $row['Db'] == '%') { $uva_mydbs['%'] = 1; break; } // loic1: avoid multiple entries for dbs if (!isset($uva_mydbs[$row['Db']])) { $uva_mydbs[$row['Db']] = 1; } } // end while PMA_DBI_free_result($rs); $uva_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['dbh']); // loic1: all databases cases - part 2 if (isset($uva_mydbs['%'])) { while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { $dblist[] = $uva_row[0]; } // end while } // end if else { while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { $uva_db = $uva_row[0]; if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) { $dblist[] = $uva_db;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -