Mysql in PHP

holder

<?php
mysql_connect("localhost","username","pwd");
mysql_set_charset("utf8");
//mysql_select_db("php34");
$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( $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 "<td><a href='2.php?db={$rec[$fieldName]}'>查看表</a></td>";
        }
        echo "</tr>";
    }
    echo "</table>";
}
?>

 

holder

posted on 2016-04-22 18:31  yeatschen  阅读(116)  评论(0编辑  收藏  举报

导航