/** * Insert data from one table to another one * * @param string the original insert statement * * @global string the database name * @global string the original table name * @global string the target database and table names * @global string the sql query used to copy the data */ function PMA_myHandler($sql_insert = '') { global $db, $table, $target; global $sql_insert_data; $sql_insert = preg_replace('~INSERT INTO (`?)' . $table . '(`?)~i', 'INSERT INTO ' . $target, $sql_insert); $result = PMA_mysql_query($sql_insert) or PMA_mysqlDie('', $sql_insert, '', $GLOBALS['err_url']); $sql_insert_data .= $sql_insert . ';' . "\n"; }
/** * Builds the SQL search query * * @param string the table name * @param string the string to search * @param integer type of search (1 -> 1 word at least, 2 -> all words, * 3 -> exact string, 4 -> regexp) * * @return array 3 SQL querys (for count, display and delete results) * * @global string the url to retun to in case of errors */ function PMA_getSearchSqls($table, $search_str, $search_option) { global $err_url; // Statement types $sqlstr_select = 'SELECT'; $sqlstr_delete = 'DELETE'; // Fields to select $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($GLOBALS['db']); $res = @PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, FALSE, $err_url); $res_cnt = $res ? mysql_num_rows($res) : 0; for ($i = 0; $i < $res_cnt; $i++) { $tblfields[] = PMA_backquote(PMA_mysql_result($res, $i, 'field')); } // end if $sqlstr_fieldstoselect = ' ' . implode(', ', $tblfields); $tblfields_cnt = count($tblfields); if ($res) { mysql_free_result($res); } // Table to use $sqlstr_from = ' FROM ' . PMA_backquote($GLOBALS['db']) . '.' . PMA_backquote($table); // Beginning of WHERE clause $sqlstr_where = ' WHERE'; $search_words = $search_option > 2 ? array($search_str) : explode(' ', $search_str); $search_wds_cnt = count($search_words); $like_or_regex = $search_option == 4 ? 'REGEXP' : 'LIKE'; $automatic_wildcard = $search_option < 3 ? '%' : ''; for ($i = 0; $i < $search_wds_cnt; $i++) { // Elimines empty values if (!empty($search_words[$i])) { for ($j = 0; $j < $tblfields_cnt; $j++) { $thefieldlikevalue[] = $tblfields[$j] . ' ' . $like_or_regex . ' \'' . $automatic_wildcard . $search_words[$i] . $automatic_wildcard . '\''; } // end for $fieldslikevalues[] = $search_wds_cnt > 1 ? '(' . implode(' OR ', $thefieldlikevalue) . ')' : implode(' OR ', $thefieldlikevalue); unset($thefieldlikevalue); } // end if } // end for $implode_str = $search_option == 1 ? ' OR ' : ' AND '; $sqlstr_where .= ' ' . implode($implode_str, $fieldslikevalues); unset($fieldslikevalues); // Builds complete queries $sql['select_fields'] = $sqlstr_select . $sqlstr_fieldstoselect . $sqlstr_from . $sqlstr_where; $sql['select_count'] = $sqlstr_select . ' COUNT(*) AS count' . $sqlstr_from . $sqlstr_where; $sql['delete'] = $sqlstr_delete . $sqlstr_from . $sqlstr_where; return $sql; }
} else { $a_query = 'DELETE FROM '; } $a_query .= PMA_backquote(htmlspecialchars(urldecode($selected[$i]))); break; case 'drop_fld': PMA_relationsCleanupColumn($db, $table, $selected[$i]); $sql_query .= (empty($sql_query) ? 'ALTER TABLE ' . PMA_backquote($table) : ',') . ' DROP ' . PMA_backquote(urldecode($selected[$i])) . ($i == $selected_cnt - 1 ? ';' : ''); break; } // end switch // All "DROP TABLE","DROP FIELD", "OPTIMIZE TABLE" and "REPAIR TABLE" // statements will be run at once below if ($query_type != 'drop_tbl' && $query_type != 'drop_fld' && $query_type != 'repair_tbl' && $query_type != 'analyze_tbl' && $query_type != 'optimize_tbl' && $query_type != 'check_tbl') { $sql_query .= $a_query . ';' . "\n"; if ($query_type != 'drop_db') { PMA_mysql_select_db($db); } $result = @PMA_mysql_query($a_query) or PMA_mysqlDie('', $a_query, FALSE, $err_url); } // end if } // end for if ($query_type == 'drop_tbl' || $query_type == 'drop_fld') { PMA_mysql_select_db($db); $result = @PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', FALSE, $err_url); } elseif ($query_type == 'repair_tbl' || $query_type == 'analyze_tbl' || $query_type == 'check_tbl' || $query_type == 'optimize_tbl') { require './sql.php'; } } }
/** * Ensures db and table are valid, else moves to the "parent" script */ require_once './libraries/db_table_exists.lib.php'; /** * Get the list of the fields of the current table */ PMA_mysql_select_db($db); $table_def = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote($table)); if (isset($primary_key)) { $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' WHERE ' . $primary_key; $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', ''); $row = PMA_mysql_fetch_array($result); } else { $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1'; $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', ''); $row = PMA_mysql_fetch_array($result); } // No row returned if (!$row) { exit; } // end if (no record returned) $default_ct = 'application/octet-stream'; if ($cfgRelation['commwork'] && $cfgRelation['mimework']) { $mime_map = PMA_getMime($db, $table); $mime_options = PMA_transformation_getOptions(isset($mime_map[urldecode($transform_key)]['transformation_options']) ? $mime_map[urldecode($transform_key)]['transformation_options'] : ''); foreach ($mime_options as $key => $option) { if (substr($option, 0, 10) == '; charset=') { $mime_options['charset'] = $option; }
$local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db) . ' LIKE \'' . addslashes($tmp[0]) . '\''; $sts_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); $sts_tmp = PMA_mysql_fetch_array($sts_result); $tables[] = $sts_tmp; } else { // table in use $tables[] = array('Name' => $tmp[0]); } } mysql_free_result($db_info_result); $sot_ready = TRUE; } } } } if (!isset($sot_ready)) { $local_query = 'SHOW TABLE STATUS FROM ' . PMA_backquote($db); $db_info_result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); if ($db_info_result != FALSE && mysql_num_rows($db_info_result) > 0) { while ($sts_tmp = PMA_mysql_fetch_array($db_info_result)) { $tables[] = $sts_tmp; } mysql_free_result($db_info_result); } } $num_tables = isset($tables) ? count($tables) : 0; /** * Displays top menu links */ echo '<!-- Top menu links -->' . "\n"; require './db_details_links.php';
/** * Sends the queries and buffers the results */ if (PMA_MYSQL_INT_VERSION >= 40003) { $res = @PMA_mysql_query('SHOW SESSION VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW SESSION VARIABLES;'); while ($row = PMA_mysql_fetch_row($res)) { $serverVars[$row[0]] = $row[1]; } @mysql_free_result($res); $res = @PMA_mysql_query('SHOW GLOBAL VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW GLOBAL VARIABLES;'); while ($row = PMA_mysql_fetch_row($res)) { $serverVarsGlobal[$row[0]] = $row[1]; } @mysql_free_result($res); } else { $res = @PMA_mysql_query('SHOW VARIABLES;', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW VARIABLES;'); while ($row = PMA_mysql_fetch_row($res)) { $serverVars[$row[0]] = $row[1]; } @mysql_free_result($res); } unset($res); unset($row); /** * Displays the page */ ?> <table border="0"> <tr> <th> <?php echo $strVar;
/** * The "PMA_RT_Table" constructor * * @param string The table name * @param integer The font size * @param integer The max. with among tables * * @global object The current PDF document * @global integer The current page number (from the * $cfg['Servers'][$i]['table_coords'] table) * @global array The relations settings * @global string The current db name * * @access private * * @see PMA_PDF, PMA_RT_Table::PMA_RT_Table_setWidth, * PMA_RT_Table::PMA_RT_Table_setHeight */ function PMA_RT_Table($table_name, $ff, &$same_wide_width) { global $pdf, $pdf_page_number, $cfgRelation, $db; $this->table_name = $table_name; $sql = 'DESCRIBE ' . PMA_backquote($table_name); $result = PMA_mysql_query($sql); if (!$result || !mysql_num_rows($result)) { $pdf->PMA_PDF_die(sprintf($GLOBALS['strPdfInvalidTblName'], $table_name)); } // load fields while ($row = PMA_mysql_fetch_array($result)) { $this->fields[] = $row[0]; } //height and width $this->PMA_RT_Table_setWidth($ff); $this->PMA_RT_Table_setHeight(); if ($same_wide_width < $this->width) { $same_wide_width = $this->width; } //x and y $sql = 'SELECT x, y FROM ' . PMA_backquote($cfgRelation['table_coords']) . ' WHERE db_name = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND table_name = \'' . PMA_sqlAddslashes($table_name) . '\'' . ' AND pdf_page_number = ' . $pdf_page_number; $result = PMA_query_as_cu($sql); if (!$result || !mysql_num_rows($result)) { $pdf->PMA_PDF_die(sprintf($GLOBALS['strConfigureTableCoord'], $table_name)); } list($this->x, $this->y) = PMA_mysql_fetch_array($result); $this->x = (double) $this->x; $this->y = (double) $this->y; // displayfield $this->displayfield = PMA_getDisplayField($db, $table_name); // index $sql = 'SHOW index FROM ' . PMA_backquote($table_name); $result = PMA_mysql_query($sql); if ($result && mysql_num_rows($result) > 0) { while ($row = PMA_mysql_fetch_array($result)) { if ($row['Key_name'] == 'PRIMARY') { $this->primary[] = $row['Column_name']; } } } // end if }
<?php /* $Id: phpinfo.php,v 2.2 2003/11/26 22:52:24 rabus Exp $ */ // vim: expandtab sw=4 ts=4 sts=4: /** * Gets core libraries and defines some variables */ require_once './libraries/grab_globals.lib.php'; require_once './libraries/common.lib.php'; /** * Displays PHP information */ $is_superuser = @PMA_mysql_query('USE mysql', $userlink); if ($is_superuser || $cfg['ShowPhpInfo']) { phpinfo(); }
} } // end if // Builds the fulltext statements and updates the table $fulltext = ''; if (isset($field_fulltext)) { $fulltext_cnt = count($field_fulltext); for ($i = 0; $i < $fulltext_cnt; $i++) { $j = $field_fulltext[$i]; $fulltext .= PMA_backquote($field_name[$j]) . ', '; } // end for $fulltext = preg_replace('@, $@', '', $fulltext); if (!empty($fulltext)) { $sql_query = 'ALTER TABLE ' . PMA_backquote($table) . ' ADD FULLTEXT (' . $fulltext . ')'; $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', '', '', $err_url); $sql_query_cpy .= "\n" . $sql_query . ';'; } } // end if // garvin: If comments were sent, enable relation stuff require_once './libraries/relation.lib.php'; require_once './libraries/transformations.lib.php'; $cfgRelation = PMA_getRelationsParam(); // garvin: Update comment table, if a comment was set. if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) { foreach ($field_comments as $fieldindex => $fieldcomment) { PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment); } } // garvin: Update comment table for mime types [MIME]
echo '<h2>' . "\n" . ' ' . (empty($dbstats) ? $strDatabases : $strDatabasesStats) . "\n" . '</h2>' . "\n"; /** * Checks if the user is allowed to do what he tries to... */ if (!empty($dbstats) && !$is_superuser) { echo $strNoPrivileges . "\n"; require_once './footer.inc.php'; } /** * Prepares the statistics */ $statistics = array(); foreach ($dblist as $current_db) { $tmp_array = array('db_name' => $current_db, 'tbl_cnt' => 0, 'data_sz' => 0, 'idx_sz' => 0, 'tot_sz' => 0); if (!empty($dbstats)) { $res = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';', $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), 'SHOW TABLE STATUS FROM ' . PMA_backquote($current_db) . ';'); while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { $tmp_array['tbl_cnt']++; $tmp_array['data_sz'] += $row['Data_length']; $tmp_array['idx_sz'] += $row['Index_length']; } } $tmp_array['tot_sz'] = $tmp_array['data_sz'] + $tmp_array['idx_sz']; $statistics[] = $tmp_array; } // avoids 'undefined index' errors if (empty($sort_by)) { $sort_by = 'db_name'; } if (empty($sort_order)) { if ($sort_by == 'db_name') {
} else { if ($num_dbs == 1) { $db = $dblist[0]; $tables = @PMA_mysql_list_tables($db); $num_tables = $tables ? @mysql_numrows($tables) : 0; $common_url_query = PMA_generate_common_url($db); if ($num_tables) { $num_tables_disp = $num_tables; } else { $num_tables_disp = '-'; } // Get additional infomation about tables for tooltip if ($cfg['ShowTooltip'] && PMA_MYSQL_INT_VERSION >= 32303 && $num_tables) { $tooltip = array(); $tooltip_name = array(); $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); while ($tmp = PMA_mysql_fetch_array($result)) { $tooltip_name[$tmp['Name']] = !empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : ''; $tmp['Comment'] = $cfg['ShowTooltipAliasTB'] ? $tmp['Name'] : $tmp['Comment']; $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')'; } // end while } // end if // garvin: Get comments from PMA comments table $db_tooltip = ''; if ($cfg['ShowTooltip'] && $cfgRelation['commwork']) { $tmp_db_tooltip = PMA_getComments($db); if (is_array($tmp_db_tooltip)) { $db_tooltip = implode(' ', $tmp_db_tooltip); }
<?php /* $Id: defines_mysql.lib.php,v 2.1 2003/11/26 22:52:23 rabus Exp $ */ // vim: expandtab sw=4 ts=4 sts=4: /** * DEFINES MYSQL RELATED VARIABLES & CONSTANTS * Overview: * PMA_MYSQL_INT_VERSION (int) - eg: 32339 instead of 3.23.39 */ if (!defined('PMA_MYSQL_INT_VERSION') && isset($userlink)) { if (!empty($server)) { $result = PMA_mysql_query('SELECT VERSION() AS version', $userlink); if ($result != FALSE && @mysql_num_rows($result) > 0) { $row = PMA_mysql_fetch_array($result); $match = explode('.', $row['version']); mysql_free_result($result); } } // end server id is defined case if (!isset($match) || !isset($match[0])) { $match[0] = 3; } if (!isset($match[1])) { $match[1] = 23; } if (!isset($match[2])) { $match[2] = 32; } if (!isset($row)) { $row['version'] = '3.23.32'; }
$fieldlist = preg_replace('@, $@', '', $fieldlist); $valuelist = preg_replace('@, $@', '', $valuelist); $query[] = 'INSERT INTO ' . PMA_backquote($table) . ' (' . $fieldlist . ') VALUES (' . $valuelist . ')'; $message = $strInsertedRows . ' '; } } // end row insertion /** * Executes the sql query and get the result, then move back to the calling * page */ $sql_query = implode(';', $query) . ';'; $total_affected_rows = 0; $last_message = ''; foreach ($query as $query_index => $single_query) { $result = PMA_mysql_query($single_query); if (!$result) { if ($cfg['IgnoreMultiSubmitErrors']) { $message .= PMA_mysql_error(); } else { $error = PMA_mysql_error(); require_once './header.inc.php'; PMA_mysqlDie($error, '', '', $err_url); } } else { if (@mysql_affected_rows()) { $total_affected_rows += @mysql_affected_rows(); } $insert_id = mysql_insert_id(); if ($insert_id != 0) { $last_message .= '<br />' . $strInsertedRowId . ' ' . $insert_id;
/** * Displays a message at the top of the "main" (right) frame * * @param string the message to display * * @global array the configuration array * * @access public */ function PMA_showMessage($message) { global $cfg; require_once './header.inc.php'; // Reloads the navigation frame via JavaScript if required if (isset($GLOBALS['reload']) && $GLOBALS['reload']) { echo "\n"; $reload_url = './left.php?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', '', '&'); ?> <script type="text/javascript" language="javascript1.2"> <!-- if (typeof(window.parent) != 'undefined' && typeof(window.parent.frames['nav']) != 'undefined') { window.parent.frames['nav'].location.replace('<?php echo $reload_url; ?> &hash=' + <?php echo $cfg['QueryFrame'] && $cfg['QueryFrameJS'] ? 'window.parent.frames[\'queryframe\'].document.hashform.hash.value' : "'" . md5($cfg['PmaAbsoluteUri']) . "'"; ?> ); } //--> </script> <?php unset($GLOBALS['reload']); } else { if (!empty($GLOBALS['table']) && $cfg['ShowTooltip']) { $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); if ($result) { $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC); $tooltip = empty($tbl_status['Comment']) ? '' : $tbl_status['Comment'] . ' '; $tooltip .= '(' . $tbl_status['Rows'] . ' ' . $GLOBALS['strRows'] . ')'; mysql_free_result($result); $md5_tbl = md5($GLOBALS['table']); echo "\n"; ?> <script type="text/javascript" language="javascript1.2"> <!-- if (typeof(document.getElementById) != 'undefined' && typeof(window.parent.frames['nav']) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'undefined' && typeof(window.parent.frames['nav'].document) != 'unknown' && (window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?> ')) && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?> ')) != 'undefined' && typeof(window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?> ').title) == 'string') { window.parent.frames['nav'].document.getElementById('<?php echo 'tbl_' . $md5_tbl; ?> ').title = '<?php echo PMA_jsFormat($tooltip, FALSE); ?> '; } //--> </script> <?php } // end if } } // end if... else if // Checks if the table needs to be repaired after a TRUNCATE query. if (isset($GLOBALS['table']) && isset($GLOBALS['sql_query']) && $GLOBALS['sql_query'] == 'TRUNCATE TABLE ' . PMA_backquote($GLOBALS['table'])) { if (!isset($tbl_status)) { $result = @PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($GLOBALS['db']) . ' LIKE \'' . PMA_sqlAddslashes($GLOBALS['table'], TRUE) . '\''); if ($result) { $tbl_status = PMA_mysql_fetch_array($result, MYSQL_ASSOC); mysql_free_result($result); } } if (isset($tbl_status) && (int) $tbl_status['Index_length'] > 1024) { @PMA_mysql_query('REPAIR TABLE ' . PMA_backquote($GLOBALS['table'])); } } unset($tbl_status); echo "\n"; ?> <div align="<?php echo $GLOBALS['cell_align_left']; ?> "> <table border="<?php echo $cfg['Border']; ?> " cellpadding="5"> <tr> <td bgcolor="<?php echo $cfg['ThBgcolor']; ?> "> <b><?php echo $message; ?> </b><br /> </td> </tr> <?php if ($cfg['ShowSQL'] == TRUE && (!empty($GLOBALS['sql_query']) || !empty($GLOBALS['display_query']))) { $local_query = !empty($GLOBALS['display_query']) ? $GLOBALS['display_query'] : ($cfg['SQP']['fmtType'] == 'none' && $GLOBALS['unparsed_sql'] != '' ? $GLOBALS['unparsed_sql'] : $GLOBALS['sql_query']); // Basic url query part $url_qpart = '?' . PMA_generate_common_url(isset($GLOBALS['db']) ? $GLOBALS['db'] : '', isset($GLOBALS['table']) ? $GLOBALS['table'] : ''); echo "\n"; ?> <tr> <td bgcolor="<?php echo $cfg['BgcolorOne']; ?> "> <?php echo "\n"; // Html format the query to be displayed // The nl2br function isn't used because its result isn't a valid // xhtml1.0 statement before php4.0.5 ("<br>" and not "<br />") // If we want to show some sql code it is easiest to create it here /* SQL-Parser-Analyzer */ $sqlnr = 1; if (!empty($GLOBALS['show_as_php'])) { $new_line = '\'<br />' . "\n" . ' . \' '; } if (isset($new_line)) { /* SQL-Parser-Analyzer */ $query_base = PMA_sqlAddslashes(htmlspecialchars($local_query)); /* SQL-Parser-Analyzer */ $query_base = preg_replace("@((\r\n)|(\r)|(\n))+@", $new_line, $query_base); } else { $query_base = $local_query; } if (!empty($GLOBALS['show_as_php'])) { $query_base = '$sql = \'' . $query_base; } else { if (!empty($GLOBALS['validatequery'])) { $query_base = PMA_validateSQL($query_base); } else { $parsed_sql = PMA_SQP_parse($query_base); $query_base = PMA_formatSql($parsed_sql, $query_base); } } // Prepares links that may be displayed to edit/explain the query // (don't go to default pages, we must go to the page // where the query box is available) // (also, I don't see why we should check the goto variable) //if (!isset($GLOBALS['goto'])) { //$edit_target = (isset($GLOBALS['table'])) ? $cfg['DefaultTabTable'] : $cfg['DefaultTabDatabase']; $edit_target = isset($GLOBALS['db']) ? isset($GLOBALS['table']) ? 'tbl_properties.php' : 'db_details.php' : ''; //} else if ($GLOBALS['goto'] != 'main.php') { // $edit_target = $GLOBALS['goto']; //} else { // $edit_target = ''; //} if (isset($cfg['SQLQuery']['Edit']) && $cfg['SQLQuery']['Edit'] == TRUE && !empty($edit_target)) { $onclick = ''; if ($cfg['QueryFrameJS'] && $cfg['QueryFrame']) { $onclick = 'onclick="focus_querywindow(\'' . urlencode($local_query) . '\'); return false;"'; } $edit_link = ' [<a href="' . $edit_target . $url_qpart . '&sql_query=' . urlencode($local_query) . '&show_query=1#querybox" ' . $onclick . '>' . $GLOBALS['strEdit'] . '</a>]'; } else { $edit_link = ''; } // Want to have the query explained (Mike Beck 2002-05-22) // but only explain a SELECT (that has not been explained) /* SQL-Parser-Analyzer */ if (isset($cfg['SQLQuery']['Explain']) && $cfg['SQLQuery']['Explain'] == TRUE) { // Detect if we are validating as well // To preserve the validate uRL data if (!empty($GLOBALS['validatequery'])) { $explain_link_validate = '&validatequery=1'; } else { $explain_link_validate = ''; } $explain_link = ' [<a href="sql.php' . $url_qpart . $explain_link_validate . '&sql_query='; if (preg_match('@^SELECT[[:space:]]+@i', $local_query)) { $explain_link .= urlencode('EXPLAIN ' . $local_query) . '">' . $GLOBALS['strExplain']; } else { if (preg_match('@^EXPLAIN[[:space:]]+SELECT[[:space:]]+@i', $local_query)) { $explain_link .= urlencode(substr($local_query, 8)) . '">' . $GLOBALS['strNoExplain']; } else { $explain_link = ''; } } if (!empty($explain_link)) { $explain_link .= '</a>]'; } } else { $explain_link = ''; } //show explain // Also we would like to get the SQL formed in some nice // php-code (Mike Beck 2002-05-22) if (isset($cfg['SQLQuery']['ShowAsPHP']) && $cfg['SQLQuery']['ShowAsPHP'] == TRUE) { $php_link = ' [<a href="sql.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query) . '&show_as_php='; if (!empty($GLOBALS['show_as_php'])) { $php_link .= '0">' . $GLOBALS['strNoPhp']; } else { $php_link .= '1">' . $GLOBALS['strPhp']; } $php_link .= '</a>]'; if (isset($GLOBALS['show_as_php']) && $GLOBALS['show_as_php'] == '1') { $php_link .= ' [<a href="sql.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query) . '">' . $GLOBALS['strRunQuery'] . '</a>]'; } } else { $php_link = ''; } //show as php if (isset($cfg['SQLValidator']['use']) && $cfg['SQLValidator']['use'] == TRUE && isset($cfg['SQLQuery']['Validate']) && $cfg['SQLQuery']['Validate'] == TRUE) { $validate_link = ' [<a href="sql.php' . $url_qpart . '&show_query=1' . '&sql_query=' . urlencode($local_query) . '&validatequery='; if (!empty($GLOBALS['validatequery'])) { $validate_link .= '0">' . $GLOBALS['strNoValidateSQL']; } else { $validate_link .= '1">' . $GLOBALS['strValidateSQL']; } $validate_link .= '</a>]'; } else { $validate_link = ''; } //validator // Displays the message echo ' ' . $GLOBALS['strSQLQuery'] . ' :'; if (!empty($edit_target)) { echo $edit_link . $explain_link . $php_link . $validate_link; } echo '<br />' . "\n"; echo ' ' . $query_base; // If a 'LIMIT' clause has been programatically added to the query // displays it if (!empty($GLOBALS['sql_limit_to_append'])) { if (!empty($GLOBALS['show_as_php'])) { echo $GLOBALS['sql_limit_to_append']; } else { if (!empty($GLOBALS['validatequery'])) { // skip the extra bit here } else { echo ' ' . PMA_formatSql(PMA_SQP_parse($GLOBALS['sql_limit_to_append'], $GLOBALS['sql_limit_to_append'])); } } } unset($local_query); //Clean up the end of the PHP if (!empty($GLOBALS['show_as_php'])) { echo '\';'; } echo "\n"; ?> </td> </tr> <?php } echo "\n"; ?> </table> </div><br /> <?php }
/** * Finds all related tables * * @param string wether to go from master to foreign or vice versa * * @return boolean always TRUE * * @global array the list of tables that we still couldn't connect * @global array the list of allready connected tables * @global string the current databse name * @global string the super user connection id * @global array the list of relation settings * * @access private */ function PMA_getRelatives($from) { global $tab_left, $tab_know, $fromclause; global $dbh, $db, $cfgRelation; if ($from == 'master') { $to = 'foreign'; } else { $to = 'master'; } $in_know = '(\'' . implode('\', \'', $tab_know) . '\')'; $in_left = '(\'' . implode('\', \'', $tab_left) . '\')'; $rel_query = 'SELECT *' . ' FROM ' . PMA_backquote($cfgRelation['relation']) . ' WHERE ' . $from . '_db = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $to . '_db = \'' . PMA_sqlAddslashes($db) . '\'' . ' AND ' . $from . '_table IN ' . $in_know . ' AND ' . $to . '_table IN ' . $in_left; if (isset($dbh)) { PMA_mysql_select_db($cfgRelation['db'], $dbh); $relations = @PMA_mysql_query($rel_query, $dbh) or PMA_mysqlDie(PMA_mysql_error($dbh), $rel_query, '', $err_url_0); PMA_mysql_select_db($db, $dbh); } else { PMA_mysql_select_db($cfgRelation['db']); $relations = @PMA_mysql_query($rel_query) or PMA_mysqlDie('', $rel_query, '', $err_url_0); PMA_mysql_select_db($db); } while ($row = PMA_mysql_fetch_array($relations)) { $found_table = $row[$to . '_table']; if (isset($tab_left[$found_table])) { $fromclause .= "\n" . ' LEFT JOIN ' . PMA_backquote($row[$to . '_table']) . ' ON ' . PMA_backquote($row[$from . '_table']) . '.' . PMA_backquote($row[$from . '_field']) . ' = ' . PMA_backquote($row[$to . '_table']) . '.' . PMA_backquote($row[$to . '_field']) . ' '; $tab_know[$found_table] = $found_table; $tab_left = PMA_arrayShort($tab_left, $found_table); } } // end while return TRUE; }
} } /** * Displays the links */ require './server_links.inc.php'; /** * Displays the sub-page heading */ echo '<h2>' . "\n" . ' ' . $strProcesslist . "\n" . '</h2>' . "\n"; /** * Sends the query and buffers the result */ $serverProcesses = array(); $sql_query = 'SHOW' . (empty($full) ? '' : ' FULL') . ' PROCESSLIST;'; $res = @PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); while ($row = PMA_mysql_fetch_array($res, MYSQL_ASSOC)) { $serverProcesses[] = $row; } @mysql_free_result($res); unset($res); unset($row); /** * Displays the page */ ?> <table border="0"> <tr> <th><a href="./server_processlist.php?<?php echo $url_query . (empty($full) ? '&full=1' : ''); ?>
/** * Displays the body of the results table * * @param integer the link id associated to the query which results have * to be displayed * @param array which elements to display * @param array the list of relations * @param array the analyzed query * * @return boolean always true * * @global string the current language * @global string the current charset for MySQL * @global integer the server to use (refers to the number in the * configuration file) * @global string the database name * @global string the table name * @global string the sql query * @global string the url to go back in case of errors * @global integer the current position in results * @global integer the maximum number of rows per page * @global array the list of fields properties * @global integer the total number of fields returned by the sql query * @global array informations used with vertical display mode * @global string the display mode (horizontal/vertical/horizontalflipped) * @global integer the number of row to display between two table headers * @global boolean whether to limit the number of displayed characters of * text type fields or not * * @access private * * @see PMA_displayTable() */ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) { global $lang, $convcharset, $server, $db, $table; global $goto; global $sql_query, $pos, $session_max_rows, $fields_meta, $fields_cnt; global $vertical_display, $disp_direction, $repeat_cells, $highlight_columns; global $dontlimitchars; global $row; // mostly because of browser transformations, to make the row-data accessible in a plugin if (!is_array($map)) { $map = array(); } ?> <!-- Results table body --> <?php echo "\n"; $row_no = 0; $vertical_display['edit'] = array(); $vertical_display['delete'] = array(); $vertical_display['data'] = array(); $vertical_display['row_delete'] = array(); // Correction uva 19991216 in the while below // Previous code assumed that all tables have keys, specifically that // the phpMyAdmin GUI should support row delete/edit only for such // tables. // Although always using keys is arguably the prescribed way of // defining a relational table, it is not required. This will in // particular be violated by the novice. // We want to encourage phpMyAdmin usage by such novices. So the code // below has been changed to conditionally work as before when the // table being displayed has one or more keys; but to display // delete/edit options correctly for tables without keys. // loic1: use 'PMA_mysql_fetch_array' rather than 'PMA_mysql_fetch_row' // to get the NULL values while ($row = PMA_mysql_fetch_array($dt_result)) { // lem9: "vertical display" mode stuff if ($row_no != 0 && $repeat_cells != 0 && !($row_no % $repeat_cells) && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { echo '<tr>' . "\n"; for ($foo_i = 0; $foo_i < $vertical_display['emptypre']; $foo_i++) { echo ' <td> </td>' . "\n"; } foreach ($vertical_display['desc'] as $key => $val) { echo $val; } for ($foo_i = 0; $foo_i < $vertical_display['emptyafter']; $foo_i++) { echo ' <td> </td>' . "\n"; } echo '</tr>' . "\n"; } // end if if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { $bgcolor = '#ffffff'; } else { $bgcolor = $row_no % 2 ? $GLOBALS['cfg']['BgcolorOne'] : $GLOBALS['cfg']['BgcolorTwo']; } if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { // loic1: pointer code part $on_mouse = ''; if (!isset($GLOBALS['printview']) || $GLOBALS['printview'] != '1') { if ($GLOBALS['cfg']['BrowsePointerColor'] != '') { $on_mouse = ' onmouseover="setPointer(this, ' . $row_no . ', \'over\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"' . ' onmouseout="setPointer(this, ' . $row_no . ', \'out\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'; } if ($GLOBALS['cfg']['BrowseMarkerColor'] != '') { $on_mouse .= ' onmousedown="setPointer(this, ' . $row_no . ', \'click\', \'' . $bgcolor . '\', \'' . $GLOBALS['cfg']['BrowsePointerColor'] . '\', \'' . $GLOBALS['cfg']['BrowseMarkerColor'] . '\');"'; } } // end if ?> <tr<?php echo $on_mouse; ?> > <?php echo "\n"; } // 1. Prepares the row (gets primary keys to use) if ($is_display['edit_lnk'] != 'nn' || $is_display['del_lnk'] != 'nn') { $primary_key = ''; $unique_key = ''; $uva_nonprimary_condition = ''; // 1.1 Results from a "SELECT" statement -> builds the // "primary" key to use in links if ($is_display['edit_lnk'] == 'ur') { for ($i = 0; $i < $fields_cnt; ++$i) { $field_flags = PMA_mysql_field_flags($dt_result, $i); $meta = $fields_meta[$i]; // do not use an alias in a condition $column_for_condition = $meta->name; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (!empty($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { $column_for_condition = $true_column; } // end if } // end if } // end while } // to fix the bug where float fields (primary or not) // can't be matched because of the imprecision of // floating comparison, use CONCAT // (also, the syntax "CONCAT(field) IS NULL" // that we need on the next "if" will work) if ($meta->type == 'real') { $condition = ' CONCAT(' . PMA_backquote($column_for_condition) . ') '; } else { $condition = ' ' . PMA_backquote($column_for_condition) . ' '; } // end if... else... // loic1: To fix bug #474943 under php4, the row // pointer will depend on whether the "is_null" // php4 function is available or not $pointer = function_exists('is_null') ? $i : $meta->name; if (!isset($row[$meta->name]) || function_exists('is_null') && is_null($row[$pointer])) { $condition .= 'IS NULL AND'; } else { if ($meta->type == 'blob' && stristr($field_flags, 'BINARY') && !empty($row[$pointer])) { $condition .= 'LIKE 0x' . bin2hex($row[$pointer]) . ' AND'; } else { $condition .= '= \'' . PMA_sqlAddslashes($row[$pointer], FALSE, TRUE) . '\' AND'; } } if ($meta->primary_key > 0) { $primary_key .= $condition; } else { if ($meta->unique_key > 0) { $unique_key .= $condition; } } $uva_nonprimary_condition .= $condition; } // end for // Correction uva 19991216: prefer primary or unique keys // for condition, but use conjunction of all values if no // primary key if ($primary_key) { $uva_condition = $primary_key; } else { if ($unique_key) { $uva_condition = $unique_key; } else { $uva_condition = $uva_nonprimary_condition; } } $uva_condition = urlencode(preg_replace('|\\s?AND$|', '', $uva_condition)); } // end if (1.1) // 1.2 Defines the urls for the modify/delete link(s) $url_query = PMA_generate_common_url($db, $table) . '&pos=' . $pos . '&session_max_rows=' . $session_max_rows . '&disp_direction=' . $disp_direction . '&repeat_cells=' . $repeat_cells . '&dontlimitchars=' . $dontlimitchars; // We need to copy the value or else the == 'both' check will always return true $propicon = (string) $GLOBALS['cfg']['PropertiesIconic']; if ($propicon == 'both') { $iconic_spacer = '<nobr>'; } else { $iconic_spacer = ''; } // 1.2.1 Modify link(s) if ($is_display['edit_lnk'] == 'ur') { // update row case // $lnk_goto = 'sql.php' // . '?' . str_replace('&', '&', $url_query) // . '&sql_query=' . urlencode($sql_query) // . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto); // to reduce the length of the URL, because of some browsers limitations: $lnk_goto = 'sql.php'; $edit_url = 'tbl_change.php' . '?' . $url_query . '&primary_key=' . $uva_condition . '&sql_query=' . urlencode($sql_query) . '&goto=' . urlencode($lnk_goto); if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) { $edit_str = $GLOBALS['strEdit']; } else { $edit_str = $iconic_spacer . '<img width="12" height="13" src="images/button_edit.png" alt="' . $GLOBALS['strEdit'] . '" title="' . $GLOBALS['strEdit'] . '" border="0" />'; if ($propicon == 'both') { $edit_str .= ' ' . $GLOBALS['strEdit'] . '</nobr>'; } } } // end if (1.2.1) if ($table == $GLOBALS['cfg']['Bookmark']['table'] && $db == $GLOBALS['cfg']['Bookmark']['db']) { $bookmark_go = '<a href="read_dump.php?' . PMA_generate_common_url($row['dbase'], '') . '&id_bookmark=' . $row['id'] . '&action_bookmark=0' . '&action_bookmark_all=1' . '&SQL=' . $GLOBALS['strExecuteBookmarked'] . ' " title="' . $GLOBALS['strExecuteBookmarked'] . '">'; if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) { $bookmark_go .= $GLOBALS['strExecuteBookmarked']; } else { $bookmark_go .= $iconic_spacer . '<img width="12" height="13" src="images/button_bookmark.png" alt="' . $GLOBALS['strExecuteBookmarked'] . '" title="' . $GLOBALS['strExecuteBookmarked'] . '" border="0" />'; if ($propicon == 'both') { $bookmark_go .= ' ' . $GLOBALS['strExecuteBookmarked'] . '</nobr>'; } } $bookmark_go .= '</a>'; } else { $bookmark_go = ''; } // 1.2.2 Delete/Kill link(s) if ($is_display['del_lnk'] == 'dr') { // delete row case $lnk_goto = 'sql.php' . '?' . str_replace('&', '&', $url_query) . '&sql_query=' . urlencode($sql_query) . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . (empty($goto) ? 'tbl_properties.php' : $goto); $del_query = urlencode('DELETE FROM ' . PMA_backquote($table) . ' WHERE') . $uva_condition . '+LIMIT+1'; $del_url = 'sql.php' . '?' . $url_query . '&sql_query=' . $del_query . '&zero_rows=' . urlencode(htmlspecialchars($GLOBALS['strDeleted'])) . '&goto=' . urlencode($lnk_goto); $js_conf = 'DELETE FROM ' . PMA_jsFormat($table) . ' WHERE ' . trim(PMA_jsFormat(urldecode($uva_condition), FALSE)) . ' LIMIT 1'; if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) { $del_str = $GLOBALS['strDelete']; } else { $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strDelete'] . '" title="' . $GLOBALS['strDelete'] . '" border="0" />'; if ($propicon == 'both') { $del_str .= ' ' . $GLOBALS['strDelete'] . '</nobr>'; } } } else { if ($is_display['del_lnk'] == 'kp') { // kill process case $lnk_goto = 'sql.php' . '?' . str_replace('&', '&', $url_query) . '&sql_query=' . urlencode($sql_query) . '&goto=main.php'; $del_url = 'sql.php?' . PMA_generate_common_url('mysql') . '&sql_query=' . urlencode('KILL ' . $row['Id']) . '&goto=' . urlencode($lnk_goto); $del_query = urlencode('KILL ' . $row['Id']); $js_conf = 'KILL ' . $row['Id']; if ($GLOBALS['cfg']['PropertiesIconic'] == FALSE) { $del_str = $GLOBALS['strKill']; } else { $del_str = $iconic_spacer . '<img width="12" height="13" src="images/button_drop.png" alt="' . $GLOBALS['strKill'] . '" title="' . $GLOBALS['strKill'] . '" border="0" />'; if ($propicon == 'both') { $del_str .= ' ' . $GLOBALS['strKill'] . '</nobr>'; } } } } // end if (1.2.2) // 1.3 Displays the links at left if required if ($GLOBALS['cfg']['ModifyDeleteAtLeft'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { require './libraries/display_tbl_links.lib.php'; } // end if (1.3) echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : ''; } // end if (1) // 2. Displays the rows' values for ($i = 0; $i < $fields_cnt; ++$i) { $meta = $fields_meta[$i]; // loic1: To fix bug #474943 under php4, the row pointer will // depend on whether the "is_null" php4 function is // available or not $pointer = function_exists('is_null') ? $i : $meta->name; // garvin: See if this column should get highlight because it's used in the // where-query. if (isset($highlight_columns) && (isset($highlight_columns[$meta->name]) || isset($highlight_columns[PMA_backquote($meta->name)]))) { $column_style = 'style="border: 1px solid ' . $GLOBALS['cfg']['BrowseMarkerColor'] . '"'; } else { $column_style = ''; } // garvin: Wrap MIME-transformations. [MIME] $default_function = 'default_function'; // default_function $transform_function = $default_function; $transform_options = array(); if ($GLOBALS['cfgRelation']['mimework'] && $GLOBALS['cfg']['BrowseMIME']) { if (isset($GLOBALS['mime_map'][$meta->name]['mimetype']) && isset($GLOBALS['mime_map'][$meta->name]['transformation']) && !empty($GLOBALS['mime_map'][$meta->name]['transformation'])) { $include_file = PMA_sanitizeTransformationFile($GLOBALS['mime_map'][$meta->name]['transformation']); if (file_exists('./libraries/transformations/' . $include_file)) { $transformfunction_name = preg_replace('@(\\.inc\\.php3?)$@i', '', $GLOBALS['mime_map'][$meta->name]['transformation']); require_once './libraries/transformations/' . $include_file; if (function_exists('PMA_transformation_' . $transformfunction_name)) { $transform_function = 'PMA_transformation_' . $transformfunction_name; $transform_options = PMA_transformation_getOptions(isset($GLOBALS['mime_map'][$meta->name]['transformation_options']) ? $GLOBALS['mime_map'][$meta->name]['transformation_options'] : ''); $meta->mimetype = str_replace('_', '/', $GLOBALS['mime_map'][$meta->name]['mimetype']); } } // end if file_exists } // end if transformation is set } // end if mime/transformation works. $transform_options['wrapper_link'] = '?' . (isset($url_query) ? $url_query : '') . '&primary_key=' . (isset($uva_condition) ? $uva_condition : '') . '&sql_query=' . (isset($sql_query) ? urlencode($sql_query) : '') . '&goto=' . (isset($sql_goto) ? urlencode($lnk_goto) : '') . '&transform_key=' . urlencode($meta->name); // n u m e r i c if ($meta->numeric == 1) { // lem9: if two fields have the same name (this is possible // with self-join queries, for example), using $meta->name // will show both fields NULL even if only one is NULL, // so use the $pointer // (works only if function_exists('is_null') // PS: why not always work with the number ($i), since // the default second parameter of // mysql_fetch_array() is MYSQL_BOTH, so we always get // associative and numeric indices? //if (!isset($row[$meta->name]) if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) { $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n"; } else { if ($row[$pointer] != '') { $vertical_display['data'][$row_no][$i] = ' <td align="right" valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '" nowrap="nowrap">'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (!empty($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { $meta->name = $true_column; } // end if } // end if } // end while } if (isset($map[$meta->name])) { // Field to display from the foreign table? if (!empty($map[$meta->name][2])) { $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]; $dispresult = PMA_mysql_query($dispsql); if ($dispresult && mysql_num_rows($dispresult) > 0) { $dispval = PMA_mysql_result($dispresult, 0); } else { $dispval = $GLOBALS['strLinkNotFound']; } } else { $dispval = ''; } // end if... else... if (isset($GLOBALS['printview']) && $GLOBALS['printview'] == '1') { $vertical_display['data'][$row_no][$i] .= ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . ' <code>[->' . $dispval . ']</code>'; } else { $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : ''; $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = ' . $row[$pointer]) . '"' . $title . '>' . ($transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta)) . '</a>'; } } else { $vertical_display['data'][$row_no][$i] .= $transform_function != $default_function ? $transform_function($row[$pointer], $transform_options, $meta) : $transform_function($row[$pointer], array(), $meta); } $vertical_display['data'][$row_no][$i] .= '</td>' . "\n"; } else { $vertical_display['data'][$row_no][$i] = ' <td align="right" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '" nowrap="nowrap"> </td>' . "\n"; } } // b l o b } else { if ($GLOBALS['cfg']['ShowBlob'] == FALSE && stristr($meta->type, 'BLOB')) { // loic1 : PMA_mysql_fetch_fields returns BLOB in place of // TEXT fields type, however TEXT fields must be displayed // even if $cfg['ShowBlob'] is false -> get the true type // of the fields. $field_flags = PMA_mysql_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $blobtext = '[BLOB'; if (isset($row[$pointer])) { $blob_size = PMA_formatByteDown(strlen($row[$pointer]), 3, 1); $blobtext .= ' - ' . $blob_size[0] . ' ' . $blob_size[1]; unset($blob_size); } $blobtext .= ']'; $blobtext = $default_function != $transform_function ? $transform_function($blobtext, $transform_options, $meta) : $default_function($blobtext, array(), $meta); $vertical_display['data'][$row_no][$i] = ' <td align="center" ' . $column_style . ' valign="top" bgcolor="' . $bgcolor . '">' . $blobtext . '</td>'; } else { //if (!isset($row[$meta->name]) if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) { $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n"; } else { if ($row[$pointer] != '') { // garvin: if a transform function for blob is set, none of these replacements will be made if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) { $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...'; } // loic1: displays all space characters, 4 space // characters for tabulations and <cr>/<lf> $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta); $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '">' . $row[$pointer] . '</td>' . "\n"; } else { $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"> </td>' . "\n"; } } } } else { //if (!isset($row[$meta->name]) if (!isset($row[$pointer]) || function_exists('is_null') && is_null($row[$pointer])) { $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"><i>NULL</i></td>' . "\n"; } else { if ($row[$pointer] != '') { // loic1: support blanks in the key $relation_id = $row[$pointer]; // nijel: Cut all fields to $cfg['LimitChars'] if (strlen($row[$pointer]) > $GLOBALS['cfg']['LimitChars'] && $dontlimitchars != 1) { $row[$pointer] = substr($row[$pointer], 0, $GLOBALS['cfg']['LimitChars']) . '...'; } // loic1: displays special characters from binaries $field_flags = PMA_mysql_field_flags($dt_result, $i); if (stristr($field_flags, 'BINARY')) { $row[$pointer] = str_replace("", '\\0', $row[$pointer]); $row[$pointer] = str_replace("", '\\b', $row[$pointer]); $row[$pointer] = str_replace("\n", '\\n', $row[$pointer]); $row[$pointer] = str_replace("\r", '\\r', $row[$pointer]); $row[$pointer] = str_replace("", '\\Z', $row[$pointer]); $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta); } else { $row[$pointer] = $default_function != $transform_function ? $transform_function($row[$pointer], $transform_options, $meta) : $default_function($row[$pointer], array(), $meta); } // garvin: transform functions may enable nowrapping: $function_nowrap = $transform_function . '_nowrap'; $bool_nowrap = $default_function != $transform_function && function_exists($function_nowrap) ? $function_nowrap($transform_options) : false; // loic1: do not wrap if date field type $nowrap = preg_match('@DATE|TIME@i', $meta->type) || $bool_nowrap ? ' nowrap="nowrap"' : ''; $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"' . $nowrap . '>'; if (isset($analyzed_sql[0]['select_expr']) && is_array($analyzed_sql[0]['select_expr'])) { foreach ($analyzed_sql[0]['select_expr'] as $select_expr_position => $select_expr) { $alias = $analyzed_sql[0]['select_expr'][$select_expr_position]['alias']; if (!empty($alias)) { $true_column = $analyzed_sql[0]['select_expr'][$select_expr_position]['column']; if ($alias == $meta->name) { $meta->name = $true_column; } // end if } // end if } // end while } if (isset($map[$meta->name])) { // Field to display from the foreign table? if (!empty($map[$meta->name][2])) { $dispsql = 'SELECT ' . PMA_backquote($map[$meta->name][2]) . ' FROM ' . PMA_backquote($map[$meta->name][3]) . '.' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($row[$pointer]) . '\''; $dispresult = @PMA_mysql_query($dispsql); if ($dispresult && mysql_num_rows($dispresult) > 0) { $dispval = PMA_mysql_result($dispresult, 0); } else { $dispval = $GLOBALS['strLinkNotFound']; } } else { $dispval = ''; } $title = !empty($dispval) ? ' title="' . htmlspecialchars($dispval) . '"' : ''; $vertical_display['data'][$row_no][$i] .= '<a href="sql.php?' . PMA_generate_common_url($map[$meta->name][3], $map[$meta->name][0]) . '&pos=0&session_max_rows=' . $session_max_rows . '&dontlimitchars=' . $dontlimitchars . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($map[$meta->name][0]) . ' WHERE ' . PMA_backquote($map[$meta->name][1]) . ' = \'' . PMA_sqlAddslashes($relation_id) . '\'') . '"' . $title . '>' . $row[$pointer] . '</a>'; } else { $vertical_display['data'][$row_no][$i] .= $row[$pointer]; } $vertical_display['data'][$row_no][$i] .= '</td>' . "\n"; } else { $vertical_display['data'][$row_no][$i] = ' <td valign="top" ' . $column_style . ' bgcolor="' . $bgcolor . '"> </td>' . "\n"; } } } } // lem9: output stored cell if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo $vertical_display['data'][$row_no][$i]; } if (isset($vertical_display['rowdata'][$i][$row_no])) { $vertical_display['rowdata'][$i][$row_no] .= $vertical_display['data'][$row_no][$i]; } else { $vertical_display['rowdata'][$i][$row_no] = $vertical_display['data'][$row_no][$i]; } } // end for (2) // 3. Displays the modify/delete links on the right if required if ($GLOBALS['cfg']['ModifyDeleteAtRight'] && ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped')) { require './libraries/display_tbl_links.lib.php'; } // end if (3) if ($disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped') { echo "\n"; ?> </tr> <?php } // end if // 4. Gather links of del_urls and edit_urls in an array for later // output if (!isset($vertical_display['edit'][$row_no])) { $vertical_display['edit'][$row_no] = ''; $vertical_display['delete'][$row_no] = ''; $vertical_display['row_delete'][$row_no] = ''; } if (!empty($del_url) && $is_display['del_lnk'] != 'kp') { $vertical_display['row_delete'][$row_no] .= ' <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . ' <input type="checkbox" id="id_rows_to_delete' . $row_no . '" name="rows_to_delete[' . $uva_condition . ']" value="' . $del_query . '" />' . "\n" . ' </td>' . "\n"; } else { unset($vertical_display['row_delete'][$row_no]); } if (isset($edit_url)) { $vertical_display['edit'][$row_no] .= ' <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . PMA_linkOrButton($edit_url, $edit_str, '') . $bookmark_go . ' </td>' . "\n"; } else { unset($vertical_display['edit'][$row_no]); } if (isset($del_url)) { $vertical_display['delete'][$row_no] .= ' <td width="10" align="center" valign="' . ($bookmark_go != '' ? 'top' : 'middle') . '" bgcolor="' . $bgcolor . '">' . "\n" . PMA_linkOrButton($del_url, $del_str, isset($js_conf) ? $js_conf : '') . ' </td>' . "\n"; } else { unset($vertical_display['delete'][$row_no]); } echo $disp_direction == 'horizontal' || $disp_direction == 'horizontalflipped' ? "\n" : ''; $row_no++; } // end while if (isset($url_query)) { $GLOBALS['url_query'] = $url_query; } return TRUE; }
?> </th> </tr> <?php } } unset($useBgcolorOne); ?> </table> </td> </tr> </table> </li> <?php } $res = PMA_mysql_query('SHOW VARIABLES LIKE "have_innodb";', $userlink); if ($res) { $row = PMA_mysql_fetch_row($res); if (!empty($row[1]) && $row[1] == 'YES') { ?> <br /> <li> <!-- InnoDB Status --> <a href="./server_status.php?<?php echo $url_query; ?> &innodbstatus=1"> <b><?php echo $strInnodbStat; ?> </b>
function PMA_mysql_list_fields_alternate($database_name, $table_name, $link_identifier = FALSE) { if ($link_identifier != FALSE) { $result = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote(PMA_convert_charset($database_name)) . '.' . PMA_backquote(PMA_convert_charset($table_name)), $link_identifier); } else { $result = PMA_mysql_query('SHOW FIELDS FROM ' . PMA_backquote(PMA_convert_charset($database_name)) . '.' . PMA_backquote(PMA_convert_charset($table_name))); } $fields = array(); while ($row = PMA_mysql_fetch_array($result)) { $fields[] = $row; } return $fields; }
* DEFINES VARIABLES & CONSTANTS * Overview: * PMA_MYSQL_INT_VERSION (int) - eg: 32339 instead of 3.23.39 * PMA_USR_OS (string) - the plateform (os) of the user * PMA_USR_BROWSER_AGENT (string) - the browser of the user * PMA_USR_BROWSER_VER (double) - the version of this browser */ // MySQL Version if (!defined('PMA_MYSQL_INT_VERSION') && isset($userlink)) { if (!empty($server)) { $result = PMA_mysql_query('SELECT VERSION() AS version'); if ($result != FALSE && @mysql_num_rows($result) > 0) { $row = PMA_mysql_fetch_array($result); $match = explode('.', $row['version']); } else { $result = @PMA_mysql_query('SHOW VARIABLES LIKE \'version\''); if ($result != FALSE && @mysql_num_rows($result) > 0) { $row = PMA_mysql_fetch_row($result); $match = explode('.', $row[1]); } } } // end server id is defined case if (!isset($match) || !isset($match[0])) { $match[0] = 3; } if (!isset($match[1])) { $match[1] = 21; } if (!isset($match[2])) { $match[2] = 0;
unset($sql_query); } $sql_query = $local_query; PMA_showMessage($strEmptyResultSet); $goto = $goto_cpy; unset($goto_cpy); if (isset($sql_query_cpy)) { $sql_query = $sql_query_cpy; unset($sql_query_cpy); } } // end if (no record returned) } } else { $local_query = 'SELECT * FROM ' . PMA_backquote($table) . ' LIMIT 1'; $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url); unset($row); } // <*****@*****.**> // retrieve keys into foreign fields, if any $cfgRelation = PMA_getRelationsParam(); $foreigners = $cfgRelation['relwork'] ? PMA_getForeigners($db, $table) : FALSE; /** * Displays the form */ // loic1: autocomplete feature of IE kills the "onchange" event handler and it // must be replaced by the "onpropertychange" one in this case $chg_evt_handler = PMA_USR_BROWSER_AGENT == 'IE' && PMA_USR_BROWSER_VER >= 5 ? 'onpropertychange' : 'onchange'; // Had to put the URI because when hosted on an https server, // some browsers send wrongly this form to the http server. ?>
/** * Displays the fields used by the "new user" form as well as the * "change login information / copy user" form. * * @param string are we creating a new user or are we just changing one? * (allowed values: 'new', 'change') * @param int the indenting level of the code * * @global array the phpMyAdmin configuration * @global ressource the database connection * * @return void */ function PMA_displayLoginInformationFields($mode = 'new', $indent = 0) { global $cfg, $userlink; $spaces = ''; for ($i = 0; $i < $indent; $i++) { $spaces .= ' '; } echo $spaces . '<tr>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <label for="select_pred_username">' . "\n" . $spaces . ' ' . $GLOBALS['strUserName'] . ':' . "\n" . $spaces . ' </label>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <select name="pred_username" id="select_pred_username" title="' . $GLOBALS['strUserName'] . '"' . "\n" . $spaces . ' onchange="if (this.value == \'any\') { username.value = \'\'; } else if (this.value == \'userdefined\') { username.focus(); username.select(); }">' . "\n" . $spaces . ' <option value="any"' . (isset($GLOBALS['pred_username']) && $GLOBALS['pred_username'] == 'any' ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyUser'] . '</option>' . "\n" . $spaces . ' <option value="userdefined"' . (!isset($GLOBALS['pred_username']) || $GLOBALS['pred_username'] == 'userdefined' ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n" . $spaces . ' </select>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <input type="text" class="textfield" name="username" class="textfield" title="' . $GLOBALS['strUserName'] . '"' . (empty($GLOBALS['username']) ? '' : ' value="' . (isset($GLOBALS['new_username']) ? $GLOBALS['new_username'] : $GLOBALS['username']) . '"') . ' onchange="pred_username.value = \'userdefined\';" />' . "\n" . $spaces . ' </td>' . "\n" . $spaces . '</tr>' . "\n" . $spaces . '<tr>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <label for="select_pred_hostname">' . "\n" . $spaces . ' ' . $GLOBALS['strHost'] . ':' . "\n" . $spaces . ' </label>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <select name="pred_hostname" id="select_pred_hostname" title="' . $GLOBALS['strHost'] . '"' . "\n"; $res = PMA_mysql_query('SELECT USER();', $userlink); $row = @PMA_mysql_fetch_row($res); @mysql_free_result($res); unset($res); if (!empty($row[0])) { $thishost = str_replace("'", '', substr($row[0], strrpos($row[0], '@') + 1)); if ($thishost == 'localhost' || $thishost == '127.0.0.1') { unset($thishost); } } echo $spaces . ' onchange="if (this.value == \'any\') { hostname.value = \'%\'; } else if (this.value == \'localhost\') { hostname.value = \'localhost\'; } ' . (empty($thishost) ? '' : 'else if (this.value == \'thishost\') { hostname.value = \'' . addslashes(htmlspecialchars($thishost)) . '\'; } ') . 'else if (this.value == \'hosttable\') { hostname.value = \'\'; } else if (this.value == \'userdefined\') { hostname.focus(); hostname.select(); }">' . "\n"; unset($row); echo $spaces . ' <option value="any"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'any' ? ' selected="selected"' : '') . '>' . $GLOBALS['strAnyHost'] . '</option>' . "\n" . $spaces . ' <option value="localhost"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'localhost' ? ' selected="selected"' : '') . '>' . $GLOBALS['strLocalhost'] . '</option>' . "\n"; if (!empty($thishost)) { echo $spaces . ' <option value="thishost"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'thishost' ? ' selected="selected"' : '') . '>' . $GLOBALS['strThisHost'] . '</option>' . "\n"; } unset($thishost); echo $spaces . ' <option value="hosttable"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'hosttable' ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseHostTable'] . '</option>' . "\n" . $spaces . ' <option value="userdefined"' . (isset($GLOBALS['pred_hostname']) && $GLOBALS['pred_hostname'] == 'userdefined' ? ' selected="selected"' : '') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n" . $spaces . ' </select>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <input type="text" class="textfield" name="hostname" value="' . (isset($GLOBALS['hostname']) ? $GLOBALS['hostname'] : '') . '" class="textfield" title="' . $GLOBALS['strHost'] . '" onchange="pred_hostname.value = \'userdefined\';" />' . "\n" . $spaces . ' </td>' . "\n" . $spaces . '</tr>' . "\n" . $spaces . '<tr>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <label for="select_pred_password">' . "\n" . $spaces . ' ' . $GLOBALS['strPassword'] . ':' . "\n" . $spaces . ' </label>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <select name="pred_password" id="select_pred_password" title="' . $GLOBALS['strPassword'] . '"' . "\n" . $spaces . ' onchange="if (this.value == \'none\') { pma_pw.value = \'\'; pma_pw2.value = \'\'; } else if (this.value == \'userdefined\') { pma_pw.focus(); pma_pw.select(); }">' . "\n" . ($mode == 'change' ? $spaces . ' <option value="keep" selected="selected">' . $GLOBALS['strKeepPass'] . '</option>' . "\n" : '') . $spaces . ' <option value="none">' . $GLOBALS['strNoPassword'] . '</option>' . "\n" . $spaces . ' <option value="userdefined"' . ($mode == 'change' ? '' : ' selected="selected"') . '>' . $GLOBALS['strUseTextField'] . ':</option>' . "\n" . $spaces . ' </select>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <input type="password" name="pma_pw" class="textfield" title="' . $GLOBALS['strPassword'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n" . $spaces . ' </td>' . "\n" . $spaces . '</tr>' . "\n" . $spaces . '<tr>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <label for="text_pma_pw2">' . "\n" . $spaces . ' ' . $GLOBALS['strReType'] . ':' . "\n" . $spaces . ' </label>' . "\n" . $spaces . ' </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '"> </td>' . "\n" . $spaces . ' <td bgcolor="' . $cfg['BgcolorTwo'] . '">' . "\n" . $spaces . ' <input type="password" name="pma_pw2" id="text_pma_pw2" class="textfield" title="' . $GLOBALS['strReType'] . '" onchange="pred_password.value = \'userdefined\';" />' . "\n" . $spaces . ' </td>' . "\n" . $spaces . '</tr>' . "\n"; }
/** * Deletes a bookmark * * @param string the current database name * @param array the bookmark parameters for the current user * @param integer the id of the bookmark to get * * @access public */ function PMA_deleteBookmarks($db, $cfgBookmark, $id) { $query = 'DELETE FROM ' . PMA_backquote($cfgBookmark['db']) . '.' . PMA_backquote($cfgBookmark['table']) . ' WHERE (user = \'' . PMA_sqlAddslashes($cfgBookmark['user']) . '\'' . ' OR user = \'\')' . ' AND id = ' . $id; if (isset($GLOBALS['dbh'])) { $result = PMA_mysql_query($query, $GLOBALS['dbh']); } else { $result = PMA_mysql_query($query); } }
/** * Outputs the content of a table in CSV format * * @param string the database name * @param string the table name * @param string the end of line sequence * @param string the url to go back in case of error * @param string SQL query for obtaining data * * @return bool Whether it suceeded * * @access public */ function PMA_exportData($db, $table, $crlf, $error_url, $sql_query) { global $what; global $add_character; global $separator; global $enclosed; global $escaped; // Gets the data from the database $result = PMA_mysql_query($sql_query) or PMA_mysqlDie('', $sql_query, '', $error_url); $fields_cnt = mysql_num_fields($result); // If required, get fields name at the first line if (isset($GLOBALS['showcsvnames']) && $GLOBALS['showcsvnames'] == 'yes') { $schema_insert = ''; for ($i = 0; $i < $fields_cnt; $i++) { if ($enclosed == '') { $schema_insert .= stripslashes(mysql_field_name($result, $i)); } else { $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, stripslashes(mysql_field_name($result, $i))) . $enclosed; } $schema_insert .= $separator; } // end for $schema_insert = trim(substr($schema_insert, 0, -1)); if (!PMA_exportOutputHandler($schema_insert . $add_character)) { return FALSE; } } // end if // Format the data while ($row = PMA_mysql_fetch_row($result)) { $schema_insert = ''; for ($j = 0; $j < $fields_cnt; $j++) { if (!isset($row[$j])) { $schema_insert .= $GLOBALS[$what . '_replace_null']; } else { if ($row[$j] == '0' || $row[$j] != '') { $row[$j] = stripslashes($row[$j]); // loic1 : always enclose fields if ($what == 'excel') { $row[$j] = ereg_replace("\r(\n)?", "\n", $row[$j]); } if ($enclosed == '') { $schema_insert .= $row[$j]; } else { $schema_insert .= $enclosed . str_replace($enclosed, $escaped . $enclosed, $row[$j]) . $enclosed; } } else { $schema_insert .= ''; } } if ($j < $fields_cnt - 1) { $schema_insert .= $separator; } } // end for if (!PMA_exportOutputHandler($schema_insert . $add_character)) { return FALSE; } } // end while mysql_free_result($result); return TRUE; }
// Adds table type, character set and comments if (!empty($tbl_type) && $tbl_type != 'Default') { $sql_query .= ' TYPE = ' . $tbl_type; $query_cpy .= "\n" . 'TYPE = ' . $tbl_type; } if (PMA_MYSQL_INT_VERSION >= 40100 && !empty($tbl_charset)) { $sql_query .= ' CHARACTER SET = ' . $tbl_charset; $query_cpy .= "\n" . 'CHARACTER SET = ' . $tbl_charset; } if (!empty($comment)) { $sql_query .= ' COMMENT = \'' . PMA_sqlAddslashes($comment) . '\''; $query_cpy .= "\n" . 'COMMENT = \'' . PMA_sqlAddslashes($comment) . '\''; } // Executes the query $error_create = false; $result = PMA_mysql_query($sql_query) or $error_create = true; if ($error_create == false) { $sql_query = $query_cpy . ';'; unset($query_cpy); $message = $strTable . ' ' . htmlspecialchars($table) . ' ' . $strHasBeenCreated; // garvin: If comments were sent, enable relation stuff require_once './libraries/relation.lib.php'; require_once './libraries/transformations.lib.php'; $cfgRelation = PMA_getRelationsParam(); // garvin: Update comment table, if a comment was set. if (isset($field_comments) && is_array($field_comments) && $cfgRelation['commwork']) { foreach ($field_comments as $fieldindex => $fieldcomment) { PMA_setComment($db, $table, $field_name[$fieldindex], $fieldcomment); } } // garvin: Update comment table for mime types [MIME]
function PMA_exportStructure($db, $table, $crlf, $error_url, $do_relation = false, $do_comments = false, $do_mime = false, $dates = false) { global $cfgRelation; /** * Gets fields properties */ PMA_mysql_select_db($db); $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($db) . '.' . PMA_backquote($table); $result = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $error_url); $fields_cnt = mysql_num_rows($result); // Check if we can use Relations (Mike Beck) if ($do_relation && !empty($cfgRelation['relation'])) { // Find which tables are related with the current one and write it in // an array $res_rel = PMA_getForeigners($db, $table); if ($res_rel && count($res_rel) > 0) { $have_rel = TRUE; } else { $have_rel = FALSE; } } else { $have_rel = FALSE; } // end if /** * Get the unique keys in the table */ $keys_query = 'SHOW KEYS FROM ' . PMA_backquote($table) . ' FROM ' . PMA_backquote($db); $keys_result = PMA_mysql_query($keys_query) or PMA_mysqlDie('', $keys_query, '', $error_url); $unique_keys = array(); while ($key = PMA_mysql_fetch_array($keys_result)) { if ($key['Non_unique'] == 0) { $unique_keys[] = $key['Column_name']; } } /** * Displays the table structure */ $buffer = $crlf . '%' . $crlf . '% ' . $GLOBALS['strStructure'] . ': ' . $table . $crlf . '%' . $crlf . ' \\begin{longtable}{'; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } $columns_cnt = 4; $alignment = '|l|c|c|c|'; if ($do_relation && $have_rel) { $columns_cnt++; $alignment .= 'l|'; } if ($do_comments && $cfgRelation['commwork']) { $columns_cnt++; $alignment .= 'l|'; } if ($do_mime && $cfgRelation['mimework']) { $columns_cnt++; $alignment .= 'l|'; } $buffer = $alignment . '} ' . $crlf; $header .= ' \\hline '; $header .= '\\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strField'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strType'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strNull'] . '}} & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strDefault'] . '}}'; if ($do_relation && $have_rel) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strLinksTo'] . '}}'; } if ($do_comments && $cfgRelation['commwork']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{' . $GLOBALS['strComments'] . '}}'; $comments = PMA_getComments($db, $table); } if ($do_mime && $cfgRelation['mimework']) { $header .= ' & \\multicolumn{1}{|c|}{\\textbf{MIME}}'; $mime_map = PMA_getMIME($db, $table, true); } $local_buffer = PMA_texEscape($table); // Table caption for first page and label if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_caption']) . '} \\label{' . str_replace('__TABLE__', $table, $GLOBALS['latex_structure_label']) . '} \\\\' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline' . $crlf . '\\endfirsthead' . $crlf; // Table caption on next pages if (isset($GLOBALS['latex_caption'])) { $buffer .= ' \\caption{' . str_replace('__TABLE__', PMA_texEscape($table), $GLOBALS['latex_structure_continued_caption']) . '} \\\\ ' . $crlf; } $buffer .= $header . ' \\\\ \\hline \\hline \\endhead \\endfoot '; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } while ($row = PMA_mysql_fetch_array($result)) { $type = $row['Type']; // reformat mysql query output - staybyte - 9. June 2001 // loic1: set or enum types: slashes single quotes inside options if (eregi('^(set|enum)\\((.+)\\)$', $type, $tmp)) { $tmp[2] = substr(ereg_replace('([^,])\'\'', '\\1\\\'', ',' . $tmp[2]), 1); $type = $tmp[1] . '(' . str_replace(',', ', ', $tmp[2]) . ')'; $type_nowrap = ''; $binary = 0; $unsigned = 0; $zerofill = 0; } else { $type_nowrap = ' nowrap="nowrap"'; $type = eregi_replace('BINARY', '', $type); $type = eregi_replace('ZEROFILL', '', $type); $type = eregi_replace('UNSIGNED', '', $type); if (empty($type)) { $type = ' '; } $binary = eregi('BINARY', $row['Type'], $test); $unsigned = eregi('UNSIGNED', $row['Type'], $test); $zerofill = eregi('ZEROFILL', $row['Type'], $test); } $strAttribute = ' '; if ($binary) { $strAttribute = 'BINARY'; } if ($unsigned) { $strAttribute = 'UNSIGNED'; } if ($zerofill) { $strAttribute = 'UNSIGNED ZEROFILL'; } if (!isset($row['Default'])) { if ($row['Null'] != '') { $row['Default'] = 'NULL'; } } else { $row['Default'] = $row['Default']; } $field_name = $row['Field']; $local_buffer = $field_name . "" . $type . "" . ($row['Null'] == '' ? $GLOBALS['strNo'] : $GLOBALS['strYes']) . "" . (isset($row['Default']) ? $row['Default'] : ''); if ($do_relation && $have_rel) { $local_buffer .= ""; if (isset($res_rel[$field_name])) { $local_buffer .= $res_rel[$field_name]['foreign_table'] . ' (' . $res_rel[$field_name]['foreign_field'] . ')'; } } if ($do_comments && $cfgRelation['commwork']) { $local_buffer .= ""; if (isset($comments[$field_name])) { $local_buffer .= $comments[$field_name]; } } if ($do_mime && $cfgRelation['mimework']) { $local_buffer .= ""; if (isset($mime_map[$field_name])) { $local_buffer .= str_replace('_', '/', $mime_map[$field_name]['mimetype']); } } $local_buffer = PMA_texEscape($local_buffer); if ($row['Key'] == 'PRI') { $pos = strpos($local_buffer, ""); $local_buffer = '\\textit{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } if (in_array($field_name, $unique_keys)) { $pos = strpos($local_buffer, ""); $local_buffer = '\\textbf{' . substr($local_buffer, 0, $pos) . '}' . substr($local_buffer, $pos); } $buffer = str_replace("", ' & ', $local_buffer); $buffer .= ' \\\\ \\hline ' . $crlf; if (!PMA_exportOutputHandler($buffer)) { return FALSE; } } // end while mysql_free_result($result); $buffer = ' \\end{longtable}' . $crlf; return PMA_exportOutputHandler($buffer); }
</form> <div id="pdflayout" class="pdflayout" style="visibility: hidden;"> <?php foreach ($array_sh_page as $key => $temp_sh_page) { $drag_x = $temp_sh_page['x']; $drag_y = $temp_sh_page['y']; $draginit .= ' Drag.init(getElement("table_' . $i . '"), null, 0, parseInt(myid.style.width)-2, 0, parseInt(myid.style.height)-5);' . "\n"; $draginit .= ' getElement("table_' . $i . '").onDrag = function (x, y) { document.edcoord.elements["c_table_' . $i . '[x]"].value = parseInt(x); document.edcoord.elements["c_table_' . $i . '[y]"].value = parseInt(y) }' . "\n"; $draginit .= ' getElement("table_' . $i . '").style.left = "' . $drag_x . 'px";' . "\n"; $draginit .= ' getElement("table_' . $i . '").style.top = "' . $drag_y . 'px";' . "\n"; $reset_draginit .= ' getElement("table_' . $i . '").style.left = "2px";' . "\n"; $reset_draginit .= ' getElement("table_' . $i . '").style.top = "' . 15 * $i . 'px";' . "\n"; $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[x]"].value = "2"' . "\n"; $reset_draginit .= ' document.edcoord.elements["c_table_' . $i . '[y]"].value = "' . 15 * $i . '"' . "\n"; $local_query = 'SHOW FIELDS FROM ' . PMA_backquote($temp_sh_page['table_name']) . ' FROM ' . PMA_backquote($db); $fields_rs = PMA_mysql_query($local_query) or PMA_mysqlDie('', $local_query, '', $err_url_0); $fields_cnt = mysql_num_rows($fields_rs); echo '<div id="table_' . $i . '" class="pdflayout_table"><u>' . $temp_sh_page['table_name'] . '</u>'; while ($row = PMA_mysql_fetch_array($fields_rs)) { echo "<br>" . htmlspecialchars($row['Field']) . "\n"; } echo '</div>' . "\n"; mysql_free_result($fields_rs); $i++; } ?> </div> <script type="text/javascript"> <!-- function init() { refreshLayout();
function PMA_getDbCollation($db) { global $userlink; if (PMA_MYSQL_INT_VERSION >= 40101) { // MySQL 4.1.0 does not support seperate charset settings // for databases. $sql_query = 'SHOW CREATE DATABASE ' . PMA_backquote($db) . ';'; $res = PMA_mysql_query($sql_query, $userlink) or PMA_mysqlDie(PMA_mysql_error($userlink), $sql_query); $row = PMA_mysql_fetch_row($res); mysql_free_result($res); $tokenized = explode(' ', $row[1]); unset($row, $res, $sql_query); for ($i = 1; $i + 3 < count($tokenized); $i++) { if ($tokenized[$i] == 'DEFAULT' && $tokenized[$i + 1] == 'CHARACTER' && $tokenized[$i + 2] == 'SET') { // We've found the character set! if (isset($tokenized[$i + 5]) && $tokenized[$i + 4] == 'COLLATE') { return $tokenized[$i + 5]; // We found the collation! } else { // We did not find the collation, so let's return the // default collation for the charset we've found. return $GLOBALS['mysql_default_collations'][$tokenized[$i + 3]]; } } } } return ''; }
* Go back to the calling script */ // Checks for a valid target script if (isset($table) && $table == '') { unset($table); } if (isset($db) && $db == '') { unset($db); } $is_db = $is_table = FALSE; if ($goto == 'tbl_properties.php') { if (!isset($table)) { $goto = 'db_details.php'; } else { PMA_mysql_select_db($db); $is_table = @PMA_mysql_query('SHOW TABLES LIKE \'' . PMA_sqlAddslashes($table, TRUE) . '\''); if (!($is_table && @mysql_numrows($is_table))) { $goto = 'db_details.php'; unset($table); } } // end if... else... } if ($goto == 'db_details.php') { if (isset($table)) { unset($table); } if (!isset($db)) { $goto = 'main.php'; } else { $is_db = @PMA_mysql_select_db($db);
if ($tbl_type == 'INNODB' && isset($curr_table[1]) && $curr_table[1] == 'InnoDB') { $selectboxall_innodb[$field_full] = $field_v; } } // end while } // end if (mysql_num_rows) } } } // end while over tables } // end if // Now find out the columns of our $table $col_query = 'SHOW COLUMNS FROM ' . PMA_backquote($table); $col_rs = PMA_mysql_query($col_query) or PMA_mysqlDie('', $col_query, '', $err_url_0); if ($col_rs && mysql_num_rows($col_rs) > 0) { while ($row = PMA_mysql_fetch_array($col_rs)) { $save_row[] = $row; } $saved_row_cnt = count($save_row); ?> <form method="post" action="tbl_relation.php"> <?php echo PMA_generate_common_hidden_inputs($db, $table); ?> <input type="hidden" name="submit_rel" value="true" /> <table> <tr> <th colspan="4" align="center"><b><?php