Hi everyone,
Some of you might remember I asked for a structure diff earlier, I want to compare 2 tables and get an alter query which would make the target table to look exactly like the original table.
I have now made a small hack which almost does this, at least it show the idea of what I want it to be.
I added the file diff_tables.php which currently takes ?db as an get argument. It shows the table in that database and you can pick 2 tables to compare and you get a hopefully working alter query. :)
I modified left.php to show a link after the num_tables, like (diff) which goes to diff_tables.php with ?db as the database.
If you want to try it out, patch your 2.3.2 version of phpmyadmin with the files, or visit http://www.egp.cx/phpMyAdmin-2.3.2/ where I put up a patched version. Please dont destroy the tables to much. :)
Some ideas of what to improve: * maintain the order of the fields * maintain keys/indexes and auto_increment fields * make it possible to diff tables between databases * make it possible to diff create table queries * create a nice graphical view over whats added/changed/dropped
Do you have any furhter suggestions?
Please comment and try it out and think about it. The code is still very hacky, and I might have re-invented the wheel in some places, but I'm not yet familiar with all libraryfiles etc.
Best regards, Eric
<?php /* Example tables to diff
# # Table structure for table `table1` #
CREATE TABLE table1 ( tbl_id int(10) unsigned NOT NULL auto_increment, str varchar(100) NOT NULL default '', params enum('y','n','k') NOT NULL default 'n', newfield varchar(10) NOT NULL default '', PRIMARY KEY (tbl_id) ) TYPE=MyISAM; # --------------------------------------------------------
# # Table structure for table `table2` #
CREATE TABLE table2 ( tbl_id int(10) unsigned NOT NULL auto_increment, str varchar(10) NOT NULL default '', params enum('y','n') NOT NULL default 'n', PRIMARY KEY (tbl_id) ) TYPE=MyISAM;
*/
/** * Gets some core libraries */ require('./libraries/grab_globals.lib.php'); $sub_part = '_export'; require('./db_details_common.php'); $url_query .= '&goto=db_details_export.php'; require('./db_details_db_info.php');
$js_to_run = 'functions.js'; require('./libraries/sqlparser.lib.php'); require('./libraries/build_dump.lib.php');
?> <h1>Diff tables</h1><br>
<FORM METHOD=POST ACTION=""> <pre> <? #echo "<pre>"; #var_dump($GLOBALS); #echo "</pre>";
function PMA_table_struct($db, $table){
$struct = array();
$res = PMA_mysql_query('DESCRIBE '.$db.'.'.$table); while( $row = PMA_mysql_fetch_array($res) ){
$struct[$row['Field']] = array( 'type' => $row['Type'], 'null' => $row['Null'], 'key' => $row['Key'], 'default'=> $row['Default'], 'extra' => $row['Extra'] );
}
return $struct;
}
function PMA_diff_length($type){
/* check length */ if( eregi('(([0-9]*))', $type, $regs) ) $length = $regs[1]; else $length = 0;
return $length; }
function PMA_diff_type($type){ return $type;
/* check type */ if( ereg('^([^(]*)', $type, $regs) ) $type = $regs[1]; else $type = '';
$type = trim($type);
return $type;
}
function PMA_alter_string($field_name, $struct, $alter_type, $first_row=false){ # echo $field_name."\n"; # var_dump($struct);
$alter = ''; if( !$first_row ) $alter.=','.chr(10); $alter.=chr(9).$alter_type.' '; $alter.=$field_name.' ';
if( $alter_type!='DROP' ){ if( $alter_type=='CHANGE' ) $alter.=' '.$field_name.' ';
$alter.=$struct['type']; $alter.=' '.$struct['null']; if( $struct['default']!="" ) $alter.=' DEFAULT "'.$struct['default'].'" '; }
return $alter; }
function PMA_diff_table_structs($original_table_struct, $target_table_struct, $target_table){
if( is_array($original_table_struct) ) reset($original_table_struct); if( is_array($target_table_struct) ) reset($target_table_struct);
$removed_fields = array(); $added_fields = array(); $modified_fields = array();
while( list($field, $field_def)=each($original_table_struct) ){ # echo $field_def['type']." - type:".PMA_diff_type($field_def['type'])."\n"; # echo "length:".PMA_diff_length($field_def['type'])."\n";
if( isset($target_table_struct[$field]) ){ $mod = array(); $target_field_def = $target_table_struct[$field]; $type = PMA_diff_type($field_def['type']); $length = PMA_diff_length($field_def['type']); $target_type = PMA_diff_type($target_field_def['type']); $target_length = PMA_diff_length($target_field_def['type']);
if( $type!=$target_type ) $mod[] = 'type'; if( $length!=$target_length ) $mod[] = 'length - '.$length.' - '.$target_length; if( $field_def['null']!=$target_field_def['null'] ) $mod[] = 'null'; if( $field_def['key']!=$target_field_def['key'] ) $mod[] = 'key'; if( $field_def['default']!=$target_field_def['default'] ) $mod[] = 'default'; if( $field_def['extra']!=$target_field_def['extra'] ) $mod[] = 'extra'; if( sizeof($mod)>0 ) $modified_fields[$field] = $mod;
}else{ $added_fields[] = $field; }
}
while( list($field, $field_def)=each($target_table_struct) ){ if( !isset($original_table_struct[$field]) ) $removed_fields[] = $field; }
# echo "\nAdded fields:\n"; # var_dump($added_fields); # echo "\nRemoved fields:\n"; # var_dump($removed_fields); # echo "\nModified fields:\n"; # var_dump($modified_fields);
if( sizeof($added_fields)>0 || sizeof($removed_fields)>0 || sizeof($modified_fields)>0 ){ $alter_query = 'ALTER TABLE '.$target_table.' '.chr(10);
$first_row = true; while( list(, $name)=each($added_fields) ){ if( isset($original_table_struct[$name]) ){ $alter_query.=PMA_alter_string($name, $original_table_struct[$name], 'ADD', $first_row); $last_row_count++; } $first_row = false; }
while( list($name, $mod)=each($modified_fields) ){ if( isset($original_table_struct[$name]) ){ $alter_query.=PMA_alter_string($name, $original_table_struct[$name], 'CHANGE', $first_row); $last_row_count++; } $first_row = false; }
while( list(, $name)=each($removed_fields) ){ $alter_query.=PMA_alter_string($name, $original_table_struct[$name], 'DROP', $first_row); $last_row_count++; $first_row = false; }
$alter_query.=';'.chr(10); }else{ $alter_query = 'No diff'; }
return $alter_query; }
if( isset($HTTP_POST_VARS['original_table']) && isset($HTTP_POST_VARS['target_table']) ){ $crlf = PMA_whichCrlf();
$original_table = $HTTP_POST_VARS['original_table']; $target_table = $HTTP_POST_VARS['target_table']; #echo "diffing ".$original_table." to ".$target_table."....<br>"; #echo "\n"; #echo "Struct for ".$original_table."\n\n"; $original_table_struct = PMA_getTableDef($db, $original_table, "\n", $err_url); # echo $original_table_struct; #echo "\n\nInfo\n"; $original_table_info = PMA_SQP_analyze(array($original_table_struct)); #var_dump($original_table_info); #echo "\n\nBuilding struct...\n\n"; $original_table_arr_struct = PMA_table_struct($db, $original_table); #var_dump($original_table_arr_struct);
#echo "\n\n\n"; #echo "Struct for ".$target_table."\n\n"; #echo PMA_getTableDef($db, $target_table, $crlf, $err_url); #echo "\n\nBuilding struct...\n\n"; $target_table_arr_struct = PMA_table_struct($db, $target_table); #var_dump($target_table_arr_struct);
#echo "\n\n\nDiff structs...\n\n\n"; ?> <TABLE cellpadding="0" cellspacing="0" border="0"> <TR> <TD valign="top"> <?echo '<b>'.$original_table.'</b>';?> <table border="<?php echo $cfg['Border']; ?>"> <tr> <td></td> <th> <?php echo ucfirst($strField); ?> </th> <th><?php echo ucfirst($strType); ?></th> <th><?php echo ucfirst($strAttr); ?></th> <th><?php echo ucfirst($strNull); ?></th> <th><?php echo ucfirst($strDefault); ?></th> <th><?php echo ucfirst($strExtra); ?></th> </tr> <? $i=0; while( list($field, $field_def)=each($original_table_arr_struct) ){ ?> <tr bgcolor="<? echo (($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);?>"> <td></td> <td> <?php echo $field; ?> </td> <td><?php echo $field_def['type']; ?></td> <td> </td> <td><?php echo $field_def['null']; ?></td> <td><?php echo $field_def['default']; ?></td> <td><?php echo $field_def['extra']; ?></td> </tr>
<? $i++; } ?> </table>
</TD> <TD align="right" valign="top"> <?echo '<b>'.$target_table.'</b>';?> <table border="<?php echo $cfg['Border']; ?>"> <tr> <td></td> <th> <?php echo ucfirst($strField); ?> </th> <th><?php echo ucfirst($strType); ?></th> <th><?php echo ucfirst($strAttr); ?></th> <th><?php echo ucfirst($strNull); ?></th> <th><?php echo ucfirst($strDefault); ?></th> <th><?php echo ucfirst($strExtra); ?></th> </tr> <? $i=0; while( list($field, $field_def)=each($target_table_arr_struct) ){ ?> <tr bgcolor="<? echo (($i % 2) ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']);?>"> <td></td> <td> <?php echo $field; ?> </td> <td><?php echo $field_def['type']; ?></td> <td> </td> <td><?php echo $field_def['null']; ?></td> <td><?php echo $field_def['default']; ?></td> <td><?php echo $field_def['extra']; ?></td> </tr> <? $i++; } ?> </table>
</TD> </TR> <tr> <td bgcolor="<?echo $cfg['BgcolorOne'];?>" colspan="2"> <b>Alter query:</b><br> <pre> <? $alter_query = PMA_diff_table_structs($original_table_arr_struct, $target_table_arr_struct, $target_table);
echo $alter_query;
?> </pre> <br> <br> </td> </tr> </TABLE>
<?
}
?> </pre> <br><br><br><br><br><br><br><br> <TABLE> <TR> <TD> original table<br> <SELECT NAME="original_table"> <? $i=0; while( $i<$num_tables ){ echo '<option value="'.$tables[$i]['Name'].'">'.$tables[$i]['Name'].'</option>'.chr(10); $i++; }
?> </SELECT> </TD> <TD> target table<br> <SELECT NAME="target_table"> <? $i=0; while( $i<$num_tables ){ echo '<option value="'.$tables[$i]['Name'].'">'.$tables[$i]['Name'].'</option>'.chr(10); $i++; }
?> </SELECT> </TD> </TR> </TABLE> <br> <br> <INPUT TYPE="submit" value="Diff">
</FORM>
<?
require('./footer.inc.php');
?>
<?php /* $Id: left.php,v 1.107 2002/08/23 08:09:55 rabus Exp $ */
/** * Gets the variables sent to this script, retains the db name that may have * been defined as startup option and include a core library */ require('./libraries/grab_globals.lib.php'); if (!empty($db)) { $db_start = $db; }
/** * Gets a core script and starts output buffering work */ require('./libraries/common.lib.php'); require('./libraries/ob.lib.php'); if ($cfg['OBGzip']) { $ob_mode = PMA_outBufferModeGet(); if ($ob_mode) { PMA_outBufferPre($ob_mode); } }
/** * Get the list and number of available databases. * Skipped if no server selected: in this case no database should be displayed * before the user choose among available ones at the welcome screen. */ if ($server > 0) { PMA_availableDatabases(); // this function is defined in "common.lib.php" } else { $num_dbs = 0; }
/** * Send http headers */ // Don't use cache (required for Opera) $now = gmdate('D, d M Y H:i:s') . ' GMT'; header('Expires: ' . $now); header('Last-Modified: ' . $now); header('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1 header('Pragma: no-cache'); // HTTP/1.0 // Define the charset to be used header('Content-Type: text/html; charset=' . $charset);
/** * Displays the frame */ // Gets the font sizes to use PMA_setFontSizes(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $available_languages[$lang][2]; ?>" lang="<?php echo $available_languages[$lang][2]; ?>" dir="<?php echo $text_dir; ?>">
<head> <title>phpMyAdmin</title> <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" /> <base<?php if (!empty($cfg['PmaAbsoluteUri'])) echo ' href="' . $cfg['PmaAbsoluteUri'] . '"'; ?> target="phpmain" /> <?php // Expandable/collapsible databases list is only used if there is more than one // database to display if ($num_dbs > 1 && !$cfg['LeftFrameLight']) { echo "\n"; ?> <!-- Collapsible tables list scripts --> <script type="text/javascript" language="javascript"> <!-- var isDOM = (typeof(document.getElementsByTagName) != 'undefined' && typeof(document.createElement) != 'undefined') ? 1 : 0; var isIE4 = (typeof(document.all) != 'undefined' && parseInt(navigator.appVersion) >= 4) ? 1 : 0; var isNS4 = (typeof(document.layers) != 'undefined') ? 1 : 0; var capable = (isDOM || isIE4 || isNS4) ? 1 : 0; // Uggly fix for Opera and Konqueror 2.2 that are half DOM compliant if (capable) { if (typeof(window.opera) != 'undefined') { capable = 0; } else if (typeof(navigator.userAgent) != 'undefined') { var browserName = ' ' + navigator.userAgent.toLowerCase(); if (browserName.indexOf('konqueror') > 0) { capable = 0; } } // end if... else if... } // end if var fontFamily = '<?php echo $left_font_family; ?>'; var fontSize = '<?php echo $font_size; ?>'; var fontBig = '<?php echo $font_bigger; ?>'; var fontSmall = '<?php echo $font_smaller; ?>'; var isServer = <?php echo ($server > 0) ? 'true' : 'false'; ?>; //--> </script> <script src="libraries/left.js" type="text/javascript" language="javascript1.2"></script> <noscript> <style type="text/css"> <!-- div {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000} .heada {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000} .headaCnt {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #000000} .parent {font-family: <?php echo $left_font_family; ?>; color: #000000; text-decoration: none} .child {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #333399; text-decoration: none} .item, .item:active, .item:hover, .tblItem, .tblItem:active {color: #333399; text-decoration: none} .tblItem:hover {color: #FF0000; text-decoration: underline} //--> </style> </noscript>
<style type="text/css"> <!-- body {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>} //--> </style> <?php } // end if ($num_dbs > 1)
else if ($num_dbs == 1) { echo "\n"; ?> <style type="text/css"> <!-- body {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>} div {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000} .heada {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000} .headaCnt {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #000000} .parent {font-family: <?php echo $left_font_family; ?>; color: #000000; text-decoration: none} .child {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #333399; text-decoration: none} .item, .item:active, .item:hover, .tblItem, .tblItem:active {font-size: <?php echo $font_smaller; ?>; color: #333399; text-decoration: none} .tblItem:hover {color: #FF0000; text-decoration: underline} //--> </style> <?php } // end if ($num_dbs == 1)
else { echo "\n"; ?> <style type="text/css"> <!-- body {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>} div {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000} input {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>} select {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; background-color: #ffffff; color: #000000} .heada {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_size; ?>; color: #000000} .parent {font-family: <?php echo $left_font_family; ?>; color: #000000; text-decoration: none} .item, .item:active, .item:hover, .tblItem, .tblItem:active {font-family: <?php echo $left_font_family; ?>; font-size: <?php echo $font_smaller; ?>; color: #333399; text-decoration: none} .tblItem:hover {color: #FF0000; text-decoration: underline} //--> </style> <?php } // end if ($num_dbs < 1)
echo "\n"; ?> </head>
<body bgcolor="<?php echo $cfg['LeftBgColor']; ?>">
<?php if ($cfg['LeftDisplayLogo']) { ?> <!-- phpMyAdmin logo --> <a href="http://www.phpmyadmin.net" target="_blank"><img src="./images/pma_logo.png" width="88" height="31" border="0" alt="phpMyAdmin" /></a> <?php } echo "\n"; ?> <!-- Link to the welcome page --> <div id="el1Parent" class="parent" style="margin-bottom: 5px"> <nobr><a class="item" href="main.php?lang=<?php echo $lang; ?>&convcharset=<?php echo $convcharset; ?>&server=<?php echo $server; ?>"><span class="heada"><b><?php echo $strHome; ?></b></span></a></nobr> </div>
<!-- Databases and tables list --> <?php // Don't display expansible/collapsible database info if: // 1. $server == 0 (no server selected) // This is the case when there are multiple servers and // '$cfg['ServerDefault'] = 0' is set. In that case, we want the welcome // screen to appear with no database info displayed. // 2. there is only one database available (ie either only one database exists // or $cfg['Servers']['only_db'] is defined and is not an array) // In this case, the database should not be collapsible/expandable if ($num_dbs > 1) {
// Light mode -> beginning of the select combo for databases if ($cfg['LeftFrameLight']) { echo ' <form method="post" action="index.php" name="left" target="_parent">' . "\n"; echo ' <input type="hidden" name="lang" value="' . $lang . '" />' . "\n"; echo ' <input type="hidden" name="convcharset" value="' . $convcharset . '" />' . "\n"; echo ' <input type="hidden" name="server" value="' . $server . '" />' . "\n"; echo ' <select name="lightm_db" onchange="this.form.submit()">' . "\n"; echo ' <option value="">(' . $strDatabases . ') ...</option>' . "\n"; $table_list = ''; $table_list_header = ''; $db_name = ''; }
$selected_db = 0;
// Gets the tables list per database for ($i = 0; $i < $num_dbs; $i++) { $db = $dblist[$i]; $j = $i + 2; if (!empty($db_start) && $db == $db_start) { $selected_db = $j; } $tables = @PMA_mysql_list_tables($db); $num_tables = ($tables) ? @mysql_numrows($tables) : 0; $common_url_query = 'lang=' . $lang . '&convcharset=' . $convcharset . '&server=' . $server . '&db=' . urlencode($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 && (!$cfg['LeftFrameLight'] || $selected_db == $j)) { $tooltip = array(); $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); while ($tmp = PMA_mysql_fetch_array($result)) { $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')'; } // end while } // end if
// No light mode -> displays the expandible/collapsible db list if ($cfg['LeftFrameLight'] == FALSE) {
// Displays the database name $on_mouse = (($cfg['LeftPointerColor'] == '') ? '' : ' onmouseover="if (isDOM || isIE4) {hilightBase('el' . $j . '', '' . $cfg['LeftPointerColor'] . '')}" onmouseout="if (isDOM || isIE4) {hilightBase('el' . $j . '', '' . $cfg['LeftBgColor'] . '')}"');
echo "\n"; echo ' <div id="el' . $j . 'Parent" class="parent"' . $on_mouse . '>';
if (!empty($num_tables)) { echo "\n"; ?> <nobr><a class="item" href="<?php echo $cfg['DefaultTabDatabase']; ?>?<?php echo $common_url_query; ?>" onclick="if (capable) {expandBase('el<?php echo $j; ?>', true); return false} else {return true}"> <img name="imEx" id="el<?php echo $j; ?>Img" src="images/plus.gif" border="0" width="9" height="9" alt="+" /></a> <?php } else { echo "\n"; ?> <nobr><img name="imEx" src="images/minus.gif" border="0" width="9" height="9" alt="-" /> <?php } echo "\n"; ?> <a class="item" href="<?php echo $cfg['DefaultTabDatabase']; ?>?<?php echo $common_url_query; ?>" onclick="if (capable) {expandBase('el<?php echo $j; ?>', false)}"> <span class="heada"><?php echo $db; ?><bdo dir="<?php echo($text_dir); ?>"> </bdo></span><span class="headaCnt">(<?php echo $num_tables_disp; ?>)</span></a></nobr> </div>
<div id="el<?php echo $j;?>Child" class="child" style="margin-bottom: 5px"<?php echo $on_mouse; ?>>
<?php // Displays the list of tables from the current database for ($t = 0; $t < $num_tables; $t++) { $table = PMA_mysql_tablename($tables, $t); $url_title = (!empty($tooltip) && isset($tooltip[$table])) ? str_replace('"', '"', $tooltip[$table]) : ''; echo "\n"; ?> <nobr><img src="images/spacer.gif" border="0" width="9" height="9" alt="" /> <a target="phpmain" href="sql.php?<?php echo $common_url_query; ?>&table=<?php echo urlencode($table); ?>&sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table)); ?>&pos=0&goto=<?php echo $cfg['DefaultTabTable']; ?>"> <img src="images/browse.gif" width="8" height="8" border="0" alt="<?php echo "$strBrowse: $table"; ?>" title="<?php echo "$strBrowse: $table"; ?>" /></a><bdo dir="<?php echo $text_dir; ?>"> </bdo> <a class="tblItem" id="tbl_<?php echo md5($table); ?>" title="<?php echo $url_title; ?>" target="phpmain" href="<?php echo $cfg['DefaultTabTable']; ?>?<?php echo $common_url_query; ?>&table=<?php echo urlencode($table); ?>"> <?php echo $table; ?></a></nobr><br /> <?php } // end for $t (tables list) echo "\n"; ?> </div> <?php echo "\n";
}
// Light mode -> displays the select combo with databases names and the // list of tables contained in the current database else { echo "\n";
// Builds the databases' names list if (!empty($db_start) && $db == $db_start) { // Gets the list of tables from the current database for ($t = 0; $t < $num_tables; $t++) { $table = PMA_mysql_tablename($tables, $t); $url_title = (!empty($tooltip) && isset($tooltip[$table])) ? str_replace('"', '"', $tooltip[$table]) : ''; $table_list .= ' <nobr><a target="phpmain" href="sql.php?' . $common_url_query . '&table=' . urlencode($table) . '&sql_query=' . urlencode('SELECT * FROM ' . PMA_backquote($table)) . '&pos=0&goto=' . $cfg['DefaultTabTable'] . '">' . "\n"; $table_list .= ' <img src="images/browse.gif" width="8" height="8" border="0" alt="' . $strBrowse . ': ' . $table . '" title="' . $strBrowse . ': ' . $table . '" /></a><bdo dir="' . $text_dir . '"> </bdo>' . "\n"; if (PMA_USR_BROWSER_AGENT == 'IE') { $table_list .= ' <span class="tblItem"><a class="tblItem" id="tbl_' . md5($table) . '" title="' . $url_title . '" target="phpmain" href="' . $cfg['DefaultTabTable'] . '?' . $common_url_query . '&table=' . urlencode($table) . '">' . $table . '</a></span></nobr><br />' . "\n"; } else { $table_list .= ' <a class="tblItem" id="tbl_' . md5($table) . '" title="' . $url_title . '" target="phpmain" href="' . $cfg['DefaultTabTable'] . '?' . $common_url_query . '&table=' . urlencode($table) . '">' . $table . '</a></nobr><br />' . "\n"; } } // end for $t (tables list)
if (!$table_list) { $table_list = ' <br /><br />' . "\n" . ' <div>' . $strNoTablesFound . '</div>' . "\n"; } $selected = ' selected="selected"';
$table_list_header .= ' <a class="item" target="phpmain" href="' . $cfg['DefaultTabDatabase'] . '?' . $common_url_query . '">' . "\n"; $table_list_header .= ' <span class="heada"><b>' . $db . '</b><bdo dir="' . $text_dir . '"> </bdo></span></a><br />' . "\n\n"; } else { $selected = ''; } // end if... else...
if (!empty($num_tables)) { echo ' <option value="' . urlencode($db) . '"' . $selected . '>' . $db . ' (' . $num_tables . ')</option>' . "\n"; } else { echo ' <option value="' . urlencode($db) . '"' . $selected . '>' . $db . ' (-)</option>' . "\n"; } // end if... else...
} // end if (light mode)
} // end for $i (db list)
// Light mode -> end of the select combo for databases and table list for // the current database if ($cfg['LeftFrameLight']) { echo ' </select>' . "\n"; echo ' <noscript><input type="submit" name="Go" value="' . $strGo . '" /></noscript>' . "\n"; echo ' </form>' . "\n";
if (!$table_list) { $table_list = ' <div>' . $strSelectADb . '</div>' . "\n"; }
// Displays the current database name and the list of tables it // contains echo "\n" . ' <hr noshade="noshade" />' . "\n\n"; echo $table_list_header; echo $table_list; echo "\n" . ' <hr noshade="noshade" />' . "\n"; }
// No light mode -> initialize some js variables for the // expandible/collapsible stuff else { ?>
<!-- Arrange collapsible/expandable db list at startup --> <script type="text/javascript" language="javascript1.2"> <!-- if (isNS4) { firstEl = 'el1Parent'; firstInd = nsGetIndex(firstEl); nsShowAll(); nsArrangeList(); } var expandedDb = '<?php echo (empty($selected_db)) ? '' : 'el' . $selected_db . 'Child'; ?>'; //--> </script> <?php
} // end if... else... (light mode)
} // end if ($server > 1)
// Case where only one database has to be displayed else if ($num_dbs == 1) { $db = $dblist[0]; $tables = @PMA_mysql_list_tables($db); $num_tables = ($tables) ? @mysql_numrows($tables) : 0; $common_url_query = 'lang=' . $lang . '&server=' . $server . '&db=' . urlencode($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(); $result = PMA_mysql_query('SHOW TABLE STATUS FROM ' . PMA_backquote($db)); while ($tmp = PMA_mysql_fetch_array($result)) { $tooltip[$tmp['Name']] = (!empty($tmp['Comment']) ? $tmp['Comment'] . ' ' : '') . '(' . (isset($tmp['Rows']) ? $tmp['Rows'] : '0') . ' ' . $strRows . ')'; } // end while } // end if
// Displays the database name echo "\n"; ?> <div id="el2Parent" class="parent"> <nobr><a class="item" href="<?php echo $cfg['DefaultTabDatabase']; ?>?<?php echo $common_url_query; ?>"> <span class="heada"><?php echo $db; ?><bdo dir="<?php echo($text_dir); ?>"> </bdo></span><span class="headaCnt">(<?php echo $num_tables_disp; ?>)(<a href="diff_tables.php?db=<?echo $db;?>">Diff</a>)</span></a></nobr> </div> <div id="el2Child" class="child" style="margin-bottom: 5px"> <?php // Displays the list of tables from the current database for ($j = 0; $j < $num_tables; $j++) { $table = PMA_mysql_tablename($tables, $j); $url_title = (!empty($tooltip) && isset($tooltip[$table])) ? str_replace('"', '"', $tooltip[$table]) : ''; echo "\n"; ?> <nobr><a target="phpmain" href="sql.php?<?php echo $common_url_query; ?>&table=<?php echo urlencode($table); ?>&sql_query=<?php echo urlencode('SELECT * FROM ' . PMA_backquote($table)); ?>&pos=0&goto=<?php echo $cfg['DefaultTabTable']; ?>"> <img src="images/browse.gif" width="8" height="8" border="0" alt="<?php echo "$strBrowse: $table"; ?>" title="<?php echo "$strBrowse: $table"; ?>" /></a><bdo dir="<?php echo $text_dir; ?>"> </bdo> <a class="tblItem" id="tbl_<?php echo md5($table); ?>" title="<?php echo $url_title; ?>" target="phpmain" href="<?php echo $cfg['DefaultTabTable']; ?>?<?php echo $common_url_query; ?>&table=<?php echo urlencode($table); ?>"> <?php echo $table; ?></a></nobr><br /> <?php } // end for $j (tables list) echo "\n"; ?> </div> <?php } // end if ($num_dbs == 1)
// Case where no database has to be displayed else { echo "\n"; echo '<p>' . $strNoDatabases . '</p>'; } // end if ($num_dbs == 0) echo "\n"; ?>
</body> </html>
<?php /** * Close MySql connections */ if (isset($dbh) && $dbh) { @mysql_close($dbh); } if (isset($userlink) && $userlink) { @mysql_close($userlink); }
/** * Sends bufferized data */ if (isset($cfg['OBGzip']) && $cfg['OBGzip'] && isset($ob_mode) && $ob_mode) { PMA_outBufferPost($ob_mode); } ?>