一個簡單的php實現的MySQL資料瀏覽器

來源:互聯網
上載者:User

這個程式可以用來瀏覽MySQL中的資料,您可以稍做修改就可以做出很不錯的MySQL瀏覽器.
*/
/*
?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('無法串連'.$host);
switch($cmd){
case 'db':
$dbs = mysql_list_dbs($con) or die('mysql_list_dbs 出錯:'.$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 出錯:'.
$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 '<hr><a href="'.$PHP_SELF.'?cmd=db">show databases</a>'.chr(13);
break;
case 'record':
$records = mysql_db_query($db,'select * from '.$table,$con) or
die('mysql_db_query 出錯:'.$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 '<hr><a href="'.$PHP_SELF.'?cmd=db">show databases</a>
<a href="'.$PHP_SELF.'?cmd=table&db='.urlencode($db).'">show tables
</a>'.chr(13);
break;
}
mysql_close($con) or die('無法與'.$host.'中斷連線');
?>
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.