PHP mysqli_field_count() Function
Definition
The mysqli_field_count() function returns the number of columns for the most recent query.
Syntax
mysqli_field_count(connection);
Parameter
Parameter | Is Required | Description |
---|---|---|
connection | Required. | MySQL connection |
Return
It returns an integer that represents the number of columns in the result set.
Example
Get the number of columns for the most recent query.
<?php/*ww w .j a va2s .c o m*/
$con=mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno($con)){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"SELECT * FROM Persons");
// Get number of columns
print(mysqli_field_count($con));
mysqli_close($con);
?>