PHP mysqli_field_count() function returns the number of columns for the most recent query.
Syntax
int mysqli_field_count(connection);
Parameter | Description |
---|---|
result : | Required parameter. Mention a result set identifier returned by mysqli_query(). |
Return Values : | Returns an integer that represents the number of fields or columns in the result set. |
<?php $con = mysqli_field_countt("localhost","user","password","db"); if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "SELECT * FROM employee"; $sql_result = mysqli_query($con, $sql); echo "Total number of columns " . mysqli_field_count($con); mysqli_close($con); ?>