PHP mysqli_field_count() Function

PHP mysqli_field_count() function returns the number of columns for the most recent query.

Syntax

int mysqli_field_count(connection);

mysqli_field_count() Function Parameter

ParameterDescription
result :Required parameter. Mention a result set identifier returned by mysqli_query().

mysqli_field_count() Function Return Value

Return Values :Returns an integer that represents the number of fields or columns in the result set.

mysqli_field_count() Function Example

<?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);
?>