A simple MySQL Data browser

Source: Internet
Author: User
Tags chr mysql urlencode
This program can be used to browse the data in MySQL, you can do a little modification can 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 (' Cannot 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. ' $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> '. chr (13);
Break
}

Mysql_close ($con) or Die (' disconnected from '. $host. ');
?>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.