例
返回字段數(columns)的結果集:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
{
// Return the
number of fields in result set
$fieldcount=mysqli_num_fields($result);
printf("Result set has %d
fields.\n",$fieldcount);
// Free result
set
mysqli_free_result($result);
}
mysqli_close($con);
?>
定義和用法
所述mysqli_num_fields()函數返回字段的數量(columns)中的結果集。
句法
mysqli_num_fields( result ) ;
參數 | 描述 |
---|---|
result | 需要。 指定由返回的結果集標識符mysqli_query() mysqli_store_result()或mysqli_use_result() |
技術細節
返回值: | 返回結果集的字段數 |
---|---|
PHP版本: | 5+ |
<PHP庫MySQLi參考