©
This document uses PHP Chinese website manual Release
(PECL maxdb >= 1.0)
maxdb_num_fields -- maxdb_result::field_count — Get the number of fields in a result
过程化风格
$result
)面向对象风格
maxdb_num_fields() returns the number of fields from specified result set.
The number of fields from a result set
Example #1 面向对象风格
<?php
$maxdb = new maxdb ( "localhost" , "MONA" , "RED" , "DEMODB" );
if ( maxdb_connect_errno ()) {
printf ( "Connect failed: %s\n" , maxdb_connect_error ());
exit();
}
if ( $result = $maxdb -> query ( "SELECT * FROM hotel.city ORDER BY zip" )) {
$field_cnt = $result -> field_count ;
printf ( "Result set has %d fields.\n" , $field_cnt );
$result -> close ();
}
$maxdb -> close ();
?>
Example #2 过程化风格
<?php
$link = maxdb_connect ( "localhost" , "MONA" , "RED" , "DEMODB" );
if ( maxdb_connect_errno ()) {
printf ( "Connect failed: %s\n" , maxdb_connect_error ());
exit();
}
if ( $result = maxdb_query ( $link , "SELECT * FROM hotel.city ORDER BY zip" )) {
$field_cnt = maxdb_num_fields ( $result );
printf ( "Result set has %d fields.\n" , $field_cnt );
maxdb_free_result ( $result );
}
maxdb_close ( $link );
?>
以上例程的输出类似于:
Result set has 3 fields.