Home > Article > Backend Development > A simple PHP implementation of MySQL data browser_PHP tutorial
This program can be used to browse data in MySQL. You can make a very good MySQL browser with a few modifications.
*/
/*
?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.':
'.chr(13);
$num_rows = mysql_num_rows($dbs) ;
for($i=0;$i<$num_rows;$i++){
$db = mysql_tablename($dbs,$i);
echo ' '.$db.'
'.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.':
'.chr(13);
$num_rows = mysql_num_rows($tables);
for ($i=0;$i<$num_rows;$i++){
$table = mysql_tablename($tables,$i);
echo ' show databases break;
case 'record':
$records = mysql_db_query($db,'select * from '.$table,$con) or
die( 'mysql_db_query error:'.$php_errmsg);
echo 'records on '.$table.':
'.chr(13);
echo '
'.mysql_field_name($records,$i).' | '.chr(13);
---|
'.$row[$i].' | '.chr(13);