標籤:
1
<form id="form1" name="form1" action="2.php" method="get"> 本資料庫中有以下表:<input type="text" name="shuru" value=""/> <input type="submit" name="sub" value="查詢"> </form><?php/** * By: Qingsong * Date: 2015/4/18 0018 * Time: 22:17 */header(‘content-type:text/html;charset=utf-8‘);$jieshou ="qingsong";define("connect",@mysql_connect("localhost","root","root"));//列出表名//echo "資料庫--".$jieshou."<br/><br/>"; $dbs = @mysql_list_tables("qingsong",connect); $rows = mysql_num_rows($dbs); $i = 0; while($i <$rows) { $db_name[$i] = mysql_tablename($dbs , $i); echo $db_name[$i]."</br>" ; $i++; }
2
<?php/** * By: Qingsong * Date: 2015/4/21 0021 * Time: 21:52 */ header(‘content-type:text/html;charset=utf-8‘);@$conn=new mysqli("localhost","root","root");if($conn->connect_error) die("資料庫連接失敗".$conn->connect_error);$shuru=$_GET["shuru"];function chaxun($shuru){ @$conn=new mysqli("localhost","root","root"); $conn->select_db("qingsong");$sql="SHOW FULL COLUMNS FROM "."$shuru";$result=$conn->query($sql);if(!$result) die("資料查詢失敗");//$row_num=$result->num_rows;//$col_num=$result->field_count;//echo" 行數為:$row_num,列數為:$col_num ";echo "<br/>";echo "<table bordercolor=#4F88EF align=center border=1><tr>";//表格while ($field=$result->fetch_field()){ echo "<th>$field->name</th>";//$field的name屬性..}echo "</tr>";while($res=$result->fetch_row()){ echo "<tr>"; foreach($res as $val) echo "<th>$val</th>"; echo "</tr>";}echo "</table>";}chaxun($shuru);?><input type="button" onclick="window.location.href=‘4.php‘" value="查看資料">
<?php/** * By: Qingsong * Date: 2015/4/21 0021 * Time: 22:39 */header(‘content-type:text/html;charset=utf-8‘);$link=mysql_connect("localhost","root","root");if(!$link) echo "資料庫沒有串連成功!";else echo "資料庫連接成功!<br/>";mysql_select_db("qingsong", $link); //選擇資料庫$q = "SELECT * FROM admin"; //SQL查詢語句mysql_query("SET NAMES utf8");$rs = mysql_query($q, $link); //擷取資料集if(!$rs){die("Valid result!");}echo "<table>";echo "<tr><td>ID</td><td>管理帳號</td><td>性別</td><td> 密碼</td><td>註冊日期</td><td>前台馬甲</td></tr>";while($row = mysql_fetch_row($rs)) echo "<tr><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td><td>$row[3]</td><td>$row[4]</td><td>$row[5]</td></tr>"; //顯示資料echo "</table>";mysql_free_result($rs); //關閉資料集echo "<br/><br/> <a href=3.php?id=qingsong>返回</a>"." <br>";
PHP+MYSQL實現輸出列印資料庫表結構和輸出表內容