mysqli::$field_count
(mysqli_field_count) Returns the number of columns that have been recently queried
field_count() / mysqli_field_count() function returns the number of columns in the last query.
Suppose we have a table called "Friends" (with 3 columns and 20 rows).
This example returns the number of columns that were last query:
<?php
$mysqli = new mysqli ( "localhost" , "my_user" , "my_password" , "my_db" ) ;
if ( $mysqli -> connect_errno ) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error ;
exit ( ) ;
}
$mysqli -> query ( "SELECT * FROM Friends" ) ;
// Get the number of columns - will return 3
$mysqli -> field_count ( ) ;
$mysqli -> close ( ) ;
?>
Suppose we have a table called "Friends" (with 3 columns and 20 rows).
This example returns the number of columns that were last query:
<?php
$con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ;
if ( mysqli_connect_errno ( ) ) {
echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ;
exit ( ) ;
}
mysqli_query ( $con , "SELECT * FROM Friends" ) ;
// Get the number of columns - will return 3
mysqli_field_count ( $con ) ;
mysqli_close ( $con ) ;
?>