";
# display the main heading
print " DB-DRILL : $rootName @ $dbHost : $thisDATABASE : $thisTABLE |
";
#
# Get a list of available databases on server
#
$dbh_rs = mysql_query("show databases");
print ""; # # If the query succeeded, display the results # IF ($dbh_rs AND mysql_num_rows($dbh_rs)) : print ""; print " | "; # # Get each database a row at a time # WHILE ( list($thisDB) = mysql_fetch_row($dbh_rs) ) : # highlight the "current" database $bgColor = ($thisDB == $thisDATABASE ? "bgcolor='$thisHILITE'" : ""); print "$thisDB
| "; ENDWHILE; print " "; # # Otherwise, display appropriate message # ELSE : print " | No databases found on system server. |
";
ENDIF;
print "";
#
# User requested a list of tables
#
IF ($thisACTION == "tbl") :
print ""; # # Make sure that a database is selected # IF ($thisDATABASE == "") : print "Database name not given: A list of tables cannot be displayed."; EXIT; ENDIF; print ""; print " "; print ""; print " Table | "; print " Type | "; print " RowFmt | "; print " Recs | "; print " FileLen | "; print " Created | "; print " LUpdate | "; print " LCheck | "; print " "; # # Get a list of tables and related information # $dbh_rs = mysql_query("show table status from $thisDATABASE"); # # If the query succeeded, display the results # IF ($dbh_rs AND mysql_num_rows($dbh_rs)) : # # Get the tables information a row at a time # $loop = 0; WHILE ($thisROW = mysql_fetch_row($dbh_rs)) : # alternate background color for each row $thisBG = ($loop++%2 ? "white" : "e0e0e0"); # display table information print ""; print " " . $thisROW[0] . " | "; print " " . $thisROW[ 1] . " | "; print " " . $thisROW[ 2] . " | "; print " " . $thisROW[ 3] . " | "; print " " . $thisROW[ 5] . " | "; print " " . $thisROW[10] . " | "; print " " . $thisROW[11] . " | "; print " " . $thisROW[12] . " | "; print " "; ENDWHILE; # # Otherwise, display appropriate message # ELSE : print "No tables were found in this database. | "; ENDIF; print " "; print " | ";
#
# User requested field information from a table
#
ELSEIF ($thisACTION== "fld") :
#
# Make sure that a database is selected
#
IF ($thisDATABASE == "") :
print "Database name not given: A list of tables cannot be displayed.";
EXIT;
ENDIF;
#
# Make sure that a table is selected
#
IF ($thisTABLE == "") :
print "Table name not given: A list of fields cannot be displayed.";
EXIT;
ENDIF;
#
# Get a list of tables for navigation purposes
#
$dbh_rs = mysql_query("show tables from $thisDATABASE");
#
# If the query succeeded, display the results
#
IF ($dbh_rs AND mysql_num_rows($dbh_rs)) :
print ""; print ""; print " "; # Retrieve table information a row at a time WHILE (list($tblName) = mysql_fetch_row($dbh_rs)) : # Highlite the "current" table $bgColor = ($tblName == $thisTABLE ? "bgcolor='$thisHILITE'" : ""); print " $tblName | "; ENDWHILE; print " "; print " | ";
#
# Otherwise, display appropriate message
#
ELSE :
print "No tables were found in this database. |
";
ENDIF;
print ""; # # Get fields list from selected table # $dbh_rs = mysql_query("show fields from $thisDATABASE.$thisTABLE"); print ""; # # If the query succeeded, display the results # IF ($dbh_rs) : print " "; print " "; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print " "; $loop = 0; # # Get/Display field information a row at a time # WHILE ( list ($col_name, $col_type, $col_null, $col_key, $col_default, $col_extra) = mysql_fetch_row($dbh_rs) ) : # alternate background color for each row $thisBG = ($loop++%2 ? "f0f0f0" : "e0e0e0"); # display field information print ""; print " $col_name | "; print " $col_type | "; print " $col_null | "; print " $col_key | "; print " $col_default | "; print " $col_extra | "; print " "; ENDWHILE; ENDIF; # # Get list of indices associated with the selected table # $dbh_rs = mysql_query("show index from $thisDATABASE.$thisTABLE"); # # If the query succeeded, display the results # IF ($dbh_rs) : print " "; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print ""; print " "; # # If no indices available, display appropriate message # IF (mysql_num_rows($dbh_rs) == 0) : print "No index has been defined for this table. | "; # # Otherwise, display index/key information # ELSE : $old_idx_name = ""; WHILE ( list ($idx_table, $idx_unique, $idx_name, $idx_seq, $idx_col, $idx_collate, $idx_card, $idx_sub, $idx_packed, $idx_null, $idx_type, $idx_comment) = mysql_fetch_row($dbh_rs) ) : # Prepare field information for "readability" $idx_unique = ($idx_unique ? "False" : "True" ); $idx_comment = ($idx_comment == "" ? "None" : $idx_comment); $idx_card = ($idx_card == "" ? "0" : $idx_card ); $idx_null = ($idx_null == "" ? "NO" : $idx_null ); # suppress repetition of index name in case of multiple field keys $thisIDXname = ($idx_name == $old_idx_name ? " " : $idx_name); $old_idx_name = $idx_name; # alternate background color for each row $thisBG = ($loop++%2 ? "f0f0f0" : "e0e0e0"); # display index information print ""; print " $thisIDXname | "; print " $idx_type | "; print " $idx_unique | "; print " $idx_col | "; print " $idx_seq | "; print " $idx_collate | "; print " $idx_card | "; print " $idx_packed | "; print " $idx_null | "; print " $idx_comment | "; print " "; ENDWHILE; ENDIF; ENDIF; # # Display the table creation script for this table # $dbh_rs = mysql_query("show create table $thisDATABASE.$thisTABLE"); # # If the query succeeded, display the results # IF ($dbh_rs) : # display header print " "; # track index name $old_idx_name = ""; # Fetch the code generated by server list ($cre_table, $cre_code) = mysql_fetch_row($dbh_rs); # "Format" the code and print it $cre_code = str_replace(chr(10), " ", $cre_code); print "$cre_code | "; ENDIF; print " "; print " | ";
ENDIF;
print "
";