mysqli_field_seek() 函數把字段指針設置爲指定字段的偏移量。php
設置結果集中第一個字段(列)的字段指針,而後經過 mysqli_fetch_field() 獲取字段信息並輸出字段名稱、表格和最大長度:mysql
<?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)) { // 獲取第一列 ("name") 的字段信息 mysqli_field_seek($result,0); $fieldinfo=mysqli_fetch_field($result); printf("字段名: %s",$fieldinfo->name); echo "<br>"; printf("表名: %s",$fieldinfo->table); echo "<br>"; printf("字段長度: %d",$fieldinfo->max_length); // 釋放結果集 mysqli_free_result($result); } mysqli_close($con); ?>