How to use mysql fetch field in PHP

In this article I am going to explain about mysql_fetch_field function in PHP.
  • 1872

PHP mysql_fetch_field() Function

The PHP mysql_fetch_field function get column information from a result and return as an object.

Syntax of mysql_fetch_field function

mysql_fetch_field(data, dataOffset)

Parameters in mysql_fetch_field function

It have two parameter:

Parameter Description
data It specifies which data pointer to use.
fieldOffset It specifies which field to start returning.

Example of mysql_fetch_field function

<html>

<body>

<?php

$con = mysql_connect("localhost","gupta","sharad");

if (!$con) {

    die('Could not connect: ' . mysql_error());

}

mysql_select_db("Mcn_Solution", $con);

$result = mysql_query('select * from Emp');

if (!$result) {

    die('Query failed: ' . mysql_error());

}

while ($property = mysql_fetch_field($result))

  {

  echo "Field name: " . $property->name . "<br />";

  echo "Table name: " . $property->table . "<br />";

  echo "Max length: " . $property->max_length . "<br />";

  echo "Not NULL: " . $property->not_null . "<br />";

  echo "Primary Key: " . $property->primary_key . "<br />";

  echo "Unique Key: " . $property->unique_key . "<br />";

  echo "Field Type: " . $property->type . "<br /> <br />";

  }

mysql_close($con);

?>

</body>

</html>


Output:

mysql-fetch-field-php.jpg

You may also want to read these related articles :
here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.