This program can be used to browse MySQL Data. You can make some modifications to make a good MySQL browser.
*/
/*
? Cmd = db
? Cmd = table & db = {}
? Cmd = record & db ={}& table = {}
*/
$ Host = 'localhost ';
$ User = 'test ';
$ Password = '';
If (! Isset ($ cmd) $ cmd = 'db ';
Switch ($ cmd ){
Case 'db ':
Break;
Case 'table ':
Break;
Case 'record ':
Break;
Default:
$ Cmd = 'db ';
Break;
}
$ Con = @ mysql_connect ($ host, $ user, $ password) or die ('unable to connect '. $ host );
Switch ($ cmd ){
Case 'db ':
$ Dbs = mysql_list_dbs ($ con) or die ('mysql _ list_dbs error: '. $ php_errmsg );
Echo 'databases on '. $ host.': <br> '. chr (13 );
$ Num_rows = mysql_num_rows ($ dbs );
For ($ I = 0; $ I <$ num_rows; $ I ++ ){
$ Db = mysql_tablename ($ dbs, $ I );
Echo '<a href = "'. $ PHP_SELF .'? Cmd = table & db = '.
Urlencode ($ db). '">'. $ db. '</a> <br>'. chr (13 );
}
Mysql_free_result ($ dbs );
Break;
Case 'table ':
$ Tables = @ mysql_list_tables ($ db, $ con) or die ('mysql _ list_tables error :'.
$ Php_errmsg );
Echo 'tables on '. $ db.' of '. $ host.': <br> '. chr (13 );
$ Num_rows = mysql_num_rows ($ tables );
For ($ I = 0; $ I <$ num_rows; $ I ++ ){
$ Table = mysql_tablename ($ tables, $ I );
Echo '<a href = "'. $ PHP_SELF .'? Cmd = record & db = '.
Urlencode ($ db). '& table ='. urlencode ($ table). '">'. $ table. '</a> <br> '.
Chr (13 );
}
Mysql_free_result ($ tables );
Echo 'Break;
Case 'record ':
$ Records = mysql_db_query ($ db, 'select * from'. $ table, $ con) or
Die ('mysql _ db_query error: '. $ php_errmsg );
Echo 'records on '. $ table.': <br> '. chr (13 );
Echo '<table border = "1" cellspacing = "0" cellpadding = "0">'. chr (13 );
Echo '<tr>'. chr (13 );
$ Num_fields = mysql_num_fields ($ records );
For ($ I = 0; $ I <$ num_fields; $ I ++)
Echo '<th>'. mysql_field_name ($ records, $ I). '</th>'. chr (13 );
Echo '</tr>'. chr (13 );
While ($ row = mysql_fetch_row ($ records )){
Echo '<tr>'. chr (13 );
For ($ I = 0; $ I <$ num_fields; $ I ++)
Echo '<td>'. $ row [$ I]. '</td>'. chr (13 );
Echo '</tr>'. chr (13 );
}
Echo '</table>'. chr (13 );
Mysql_free_result ($ records );
Echo '<A href = "'. $ PHP_SELF .'? Cmd = table & db = '. urlencode ($ db).' "> show tables
</A> '. chr (13 );
Break;
}
Mysql_close ($ con) or die ('cannot be disconnected from'. $ host ');
?>