Name

mysql_fetch_field

Synopsis

object mysql_fetch_field(qresource query [, int attribute ])

Returns an object containing metadata about an attribute associated with a query resource handle. The first argument is a query resource handle returned from a prior call to mysql_list_fields( ), mysql_query( ), or mysql_unbuffered_query( ). The second optional parameter indicates which attribute in the result set is required. If no second argument is provided, metadata about the first attribute that has not yet been retrieved is returned. Thus, successive calls to mysql_fetch_fields( ) can be used to retrieve information about all the attributes in a query result set.

The properties of the object returned by the function are:

name

The attribute name

table

The name of the table to which the attribute belongs

max_length

The maximum length of the attribute

not_null

Set to one if the attribute cannot be NULL

primary_key

Set to one if the attribute forms part of a primary key

unique_key

Set to one if the attribute is a unique key

multiple_key

Set to one if the attribute is a non-unique key

numeric

Set to one if the attribute is a numeric type

blob

Set to one if the attribute is a BLOB type

type

The type of the attribute

unsigned

Set to one if the attribute is an unsigned numeric type

zerofill

Set to one if the numeric column is zero filled

Example

<?php $connection = mysql_connect("localhost", "fred", "shhh"); $result = mysql_list_fields("wedding", "presents"); echo "Presents table attributes:\n"; ...

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.