PHP 教程
取得所有字段的字段信息,然后通過 mysqli_field_tell() 取得當(dāng)前字段并輸出字段名稱、表格和最大長度:
<?php // 假定數(shù)據(jù)庫用戶名:root,密碼:123456,數(shù)據(jù)庫:JSON $con=mysqli_connect("localhost","root","123456","JSON"); 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)) ????{ ????????// 獲取當(dāng)前字段信息 ????????$currentfield=mysqli_field_tell($result); ???????? ????????printf("列 %d", $currentfield); ????????echo "<br>"; ????????printf("字段名: %s", $fieldinfo->name); ????????echo "<br>"; ????????printf("表名: %s", $fieldinfo->table); ????????echo "<br>"; ????} ????// 釋放結(jié)果集 ????mysqli_free_result($result); } mysqli_close($con); ?>
mysqli_field_tell() 函數(shù)返回字段指針的位置。
參數(shù) | 描述 |
---|---|
result | 必需。規(guī)定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的結(jié)果集標(biāo)識(shí)符。 |
返回值: | 返回字段指針的當(dāng)前偏移量。 |
---|---|
PHP 版本: | 5+ |