Use the mysql_fetch_field function to get information about a field in a result set.
Fields are numbered starting with zero. The return value is an object with properties
described in Table 13.7.
If the field argument is left out, the next field in the set will be returned. This behavior
allows you to loop through each field easily.
Table 13.7. Properties of mysql_fetch_field Object
Property Description
blob (^) TRUE if the column is a blob
max_length (^) Maximum length
multiple_key (^) TRUE if the column is a nonunique key
name (^) Name of the column
not_null (^) TRUE if the column cannot be null
numeric (^) TRUE if the column is numeric
primary_key (^) TRUE if the column is a primary key
table (^) Name of the table
type (^) Type of the column
unique_key (^) TRUE if the column is a unique key
unsigned (^) TRUE if the column is unsigned
zerofill (^) TRUE if the column is zero-filled
<?
//connect to server as freetrade user, no password
$dbLink = mysql_pconnect("localhost", "freetrade", "");
//select the 'freetrade' database
mysql_select_db("freetrade", $dbLink);
//get everything from address table
$Query = "SELECT * ".
"FROM address a, user u ".
"WHERE u.Address = a.ID ";
$dbResult = mysql_query($Query, $dbLink);
// get description of each field
while($Field = mysql_fetch_field($dbResult))
{
print("$Field->table, $Field->name, $Field->type
\n");
}
?>
array mysql_fetch_lengths(integer result)
Use mysql_fetch_lengths to get an array of the maximum lengths for each of the fields
in a result set.