PHP mysqli_field_count() Function
In this chapter you will learn:
- Definition for PHP mysqli_field_count() Function
- Syntax for PHP mysqli_field_count() Function
- Parameter for PHP mysqli_field_count() Function
- Return for PHP mysqli_field_count() Function
- Example - Get the number of columns for the most recent query
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/*j av a 2 s . co 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);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_field_seek() Function
- Syntax for PHP mysqli_field_seek() Function
- Parameter for PHP mysqli_field_seek() Function
- Return for PHP mysqli_field_seek() Function
- Example - sets the field cursor to the first column in the result set
Home » PHP Tutorial » PHP MySQLi Functions