<?php$db = 'ecs_e94f4d07d259f246';$conn = open_db($db);$data = show_db($db);echo($data);// 擷取資料庫資訊function show_db($db) { $data = '<h1>資料庫設計說明書('.$db.')</h1>'; $tables = show_tables(); foreach($tables as $key=>$val) { $table = current($val); $data .= '<table border="1" cellspacing="0">'; $data .= '<caption><h2>' . $table . '</h2></caption>'; $data .= '<tr bgcolor="#cccccc"><th width="130">Field</th><th width="200">Desc</th><th width="180">Type</th><th width="80">Null</th><th width="80">Key</th><th width="80">Default</th><th width="120">Extra</th></tr>'; $fields = describe($table); foreach($fields as $item) { $data .= '<tr><td>'.$item['Field'].'</td><td> </td><td>'.$item['Type'].'</td><td>'.$item['Null'].'</td><td>'.($item['Key'] ? $item['Key'] : ' ').'</td><td>'.($item['Default'] ? $item['Default'] : ' ').'</td><td>'.($item['Extra'] ? $item['Extra'] : ' ').'</td></tr>'; } $data .= '</table>'; $data .= '<br/>'; } $data .= ''; return $data;}// 串連資料庫function open_db($db) { $conn = mysql_connect('127.0.0.1', 'root', 'mysql'); if (!$conn) { die('Could not connect: ' . mysql_error()); } if (!mysql_select_db($db, $conn)) { die ('Can\'t use ' . $db . ' : ' . mysql_error()); } return $conn;}// 關閉資料庫連接function close_db($con) { mysql_close($con);}// 擷取全部資料表function show_tables() { $sql = "SHOW TABLES"; return query($sql);}// 擷取資料表結構資訊function describe($table) { $sql = "DESCRIBE $table"; return query($sql);}// 執行SQLfunction query($sql) { $res = mysql_query($sql, $GLOBALS['conn']); if(!$res) { die('Invalid query: ' . mysql_error()); } $list = array(); while ($row = mysql_fetch_assoc($res)) { $list[] = $row; } return $list; }?>