PHP mysqli_fetch_fields() Function

PHP mysqli_fetch_fields() function returns an array of objects representing the fields in a result set.

Syntax

array mysqli_fetch_fields(result);;

mysqli_fetch_fields() Function Parameter

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

mysqli_fetch_fields() Function Return Value

Return Values :Returns an array of objects containing field or column information. 0 if information not available.

mysqli_fetch_fields() Function Example

<?php
$con = mysqli_fetch_fieldst("localhost","user","password","db");

if (mysqli_connect_errno())
{
	echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql = "SELECT fname, lname FROM employee";
$sql_result = mysqli_query($con, $sql);

$field_info = mysqli_fetch_fields($sql_result);

foreach ($field_info as $val)
{
 echo "Name : ". $val->name;
 echo "Table : " . $val->table;
}

mysql_free_result($sql_result);

mysqli_close($con);
?>