PHP MySQL Functions to get details of the fields of a table

We can get all the details about the fields used in a table by using the mysql_fetch_field() function. This function returns an object and using that we can get required information about the field. Here in the query we have to specify the fields for which the detail information is required. We also can use symbol * to get information on all the fields of the table. If we are mentioning field names then we will only get details of those fields only.

Here we will use mysql_num_fields() to get the number of fields there in the table. Here is the code to display details of the fields.
<?
$query="select * from student";
$result=mysql_query($query) or die( "query failed");

$i = 0;
while ($i < mysql_num_fields ($result)) {
$row = mysql_fetch_field ($result);

echo "<PRE>
Information for column Name:<b>$row->name</b> 
type: $row->type 
max_length: $row->max_length 
multiple_key: $row->multiple_key
name: $row->name
not_null: $row->not_null
numeric: $row->numeric
primary_key: $row->primary_key
table: $row->table
unique_key: $row->unique_key
unsigned: $row->unsigned
zerofill: $row->zerofill
blob: $row->blob
</PRE>";
$i++;
}
mysql_free_result ($result);
?>


The out put of above code is given below for one field only, but same way for other fields also we can get the result.

Information for column Name:name
type: string
max_length: 11
multiple_key: 0
name: name
not_null: 1
numeric: 0
primary_key: 0
table: student
unique_key: 0
unsigned: 0
zerofill: 0
blob: 0


plus2net.com



Post your comments , suggestion , error , requirements etc here .





SQL Video Tutorials










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer