©
本文檔使用 php中文網手册 發布
(PHP 5)
mysqli_result::$field_count -- mysqli_num_fields — Get the number of fields in a result
面向对象风格
过程化风格
$result
)Returns the number of fields from specified result set.
result
仅以过程化样式:由 mysqli_query() , mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识。
The number of fields from a result set.
Example #1 面向对象风格
<?php
$mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "world" );
if ( mysqli_connect_errno ()) {
printf ( "Connect failed: %s\n" , mysqli_connect_error ());
exit();
}
if ( $result = $mysqli -> query ( "SELECT * FROM City ORDER BY ID LIMIT 1" )) {
$field_cnt = $result -> field_count ;
printf ( "Result set has %d fields.\n" , $field_cnt );
$result -> close ();
}
$mysqli -> close ();
?>
Example #2 过程化风格
<?php
$link = mysqli_connect ( "localhost" , "my_user" , "my_password" , "world" );
if ( mysqli_connect_errno ()) {
printf ( "Connect failed: %s\n" , mysqli_connect_error ());
exit();
}
if ( $result = mysqli_query ( $link , "SELECT * FROM City ORDER BY ID LIMIT 1" )) {
$field_cnt = mysqli_num_fields ( $result );
printf ( "Result set has %d fields.\n" , $field_cnt );
mysqli_free_result ( $result );
}
mysqli_close ( $link );
?>
以上例程会输出:
Result set has 5 fields.