PHP mysqli_fetch_field() 函數

返回結果集中下一字段(列),而後輸出每一個字段名稱、表格和最大長度:php

<?php 
// 假定數據庫用戶名:root,密碼:123456,數據庫:RUNOOB 
$con=mysqli_connect("localhost","root","123456","RUNOOB"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "鏈接 MySQL 失敗: " . mysqli_connect_error(); 
} 

$sql="SELECT name,url FROM websites ORDER BY alexa";


if ($result=mysqli_query($con,$sql))
{
    // 獲取全部列的字段信息
    while ($fieldinfo = mysqli_fetch_field($result)) {

        printf("字段名:     %s\n", $fieldinfo->name);
        echo "<br>";
        printf("數據表:    %s\n", $fieldinfo->table);
        echo "<br>";
        printf("最大長度: %d\n", $fieldinfo->max_length);
        echo "<br>";
    }
    // 釋放結果集
    mysqli_free_result($result);
}

mysqli_close($con);
?>
相關文章
相關標籤/搜索