PHP mysqli_fetch_field_direct() Function

PHP mysqli_fetch_field_direct() function is used to fetch meta-data for a single field as an object.


object mysqli_fetch_field_direct(result,colno);;

mysqli_fetch_field_direct() Function Parameter

result :Required parameter. Mention a result set identifier returned by mysqli_query().
colno :Required parameter. Mention field or column number between 0 and number of fields - 1.

mysqli_fetch_field_direct() Function Return Value

Return Values :Returns an object with columns or fields information. 0 if no info is available.

mysqli_fetch_field_direct() Function Example

$con = mysqli_fetch_field_directt("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);

while ($row = mysqli_fetch_field_direct($sql_result)) {
  // Get field information for "fname"
  $field_info = mysqli_fetch_field_direct($result,3);

  echo "Name : " . $field_info->name;
  echo "Table Name: " . $field_info->table;