1showdatabases.php
<?php
mysql_connect("localhost", "root" ,'123456');
mysql_set_charset("utf8");
$sql = "show databases;";
$result = mysql_query($sql);
if($result === false){
echo "执行失败";
}
else{
$fieldCount = mysql_num_fields( $result ); //取得结果集的列数
echo "<table border='1'>";
//表头
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<th>" . $fieldName . "</th>";
}
echo "<th>动作</th>";
echo "</tr>";
while( $arr = mysql_fetch_assoc( $result ) ){
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<td>" . $arr[$fieldName] . "</td>";
echo "<td><a href='2show_tables.php?db={$arr[$fieldName]}'>查看表</a></td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
2show_tables.php
<?php
mysql_connect("localhost", "root" ,'123456');
mysql_set_charset("utf8");
$db = $_GET['db'];
mysql_select_db($db);
$sql = "show tables;";
$result = mysql_query($sql);
if($result === false){
echo "执行失败" . mysql_error();
}
else{
$fieldCount = mysql_num_fields( $result ); //取得结果集的列数
echo "<table border='1'>";
//表头
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<th>" . $fieldName . "</th>";
}
echo "<th>动作</th>";
echo "</tr>";
while( $arr1 = mysql_fetch_assoc( $result ) ){
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<td>" . $arr1[$fieldName] . "</td>";
echo "<td><a href='3show_data.php?db=$db&tab={$arr1[$fieldName]}'>查看数据</a></td>";
echo "<td><a href='4show_struct.php?db=$db&tab={$arr1[$fieldName]}'>查看结构</a></td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
3show_data.php
<?php
mysql_connect("localhost", "root" ,'123456');
mysql_set_charset("utf8");
$db = $_GET['db'];
$tab = $_GET['tab'];
mysql_select_db($db);
$sql = "select * from $tab";
$result = mysql_query($sql);
if($result === false){
echo "执行失败" . mysql_error();
}
else{
$fieldCount = mysql_num_fields( $result ); //取得结果集的列数
echo "<table border='1'>";
//表头
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<th>" . $fieldName . "</th>";
}
echo "</tr>";
while( $rec = mysql_fetch_assoc( $result ) ){
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<td>" . $rec[$fieldName] . "</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
4show_struct.php
<?php
mysql_connect("localhost", "root" ,'123456');
mysql_set_charset("utf8");
$db = $_GET['db'];
$tab = $_GET['tab'];
mysql_select_db($db);
$sql = "desc $tab";
$result = mysql_query($sql);
if($result === false){
echo "执行失败" . mysql_error();
}
else{
$fieldCount = mysql_num_fields( $result ); //取得结果集的列数
echo "<table border='1'>";
//表头
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<th>" . $fieldName . "</th>";
}
echo "</tr>";
while( $rec = mysql_fetch_assoc( $result ) ){
echo "<tr>";
for($i = 0; $i < $fieldCount; ++$i){
$fieldName = mysql_field_name($result, $i);//取得第i个列名;
echo "<td>" . $rec[$fieldName] . "</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>