(7) Database information functions (2):
1, Mysql_fetch_field ()
Format: Object Mysql_fetch_field (int query, int [field_offset]);
Returns 1 objects, a hash table, labeled:
Table: Tables Name
Name: Field name
Max_length: Maximum length of this field
Not_null: Field NOT NULL returns 1, otherwise returns 0
Primary_key: Field Primary key returns 1, otherwise returns 0
Unique_key: Field Unique key returns 1, otherwise returns 0
Multiple_key: field is not unique key returns 1, otherwise returns 0
Numeric: Field numeric returns 1, otherwise returns 0
Blob: Field BLOB returns 1, otherwise returns 0
Type: Types of fields
Unsigned: Field unsigned returns 1, otherwise returns 0
Zerofill: Field Zero filled returns 1, otherwise returns 0
The reference format is: Object name-> subscript name
Use this function to get the table name, field name, type ....
Example:
<?php
$query = mysql_query ($sql, $connect);
while ($object = Mysql_fetch_field ($query))
{
echo "Table name:". $object->table. " <br> ";
echo "Field name:". $object->name. " <br> ";
echo "PRIMARY key:". $object->primary_key. " <br> ";
echo "NOT null:". $object->not_null. " <br> ";
echo "field type:". $object->type. " <br> ";
echo "Field max Length:". $object->max_length. " <br> ";
}
?>
Note: The hash table starts with 0 coordinates, that is, the first field is the 0 items in the Hashtable.
If we want to get directly to the third or third field of the hash table, you can use the following format:
<?php
$query = mysql_query ($sql, $connect);
$object = Mysql_fetch_field ($query, 2);
echo "Table name:". $object->table. " <br> ";
echo "Field name:". $object->name. " <br> ";
echo "PRIMARY key:". $object->primary_key. " <br> ";
echo "NOT null:". $object->not_null. " <br> ";
echo "field type:". $object->type. " <br> ";
echo "Field max Length:". $object->max_length. " <br> ";
?>
In fact, this can also be done by the following function to achieve the same goal.
2, Mysql_field_seek ()
Format: int mysql_field_seek (int $query, int field_offset);
Moves the cursor over the specified field.
Example:
<?php
$query = mysql_query ($sql, $connect);
$seek = Mysql_field_seek ($query, 2);
$object = Mysql_fetch_field ($query);
echo "Table name:". $object->table. " <br> ";
echo "Field name:". $object->name. " <br> ";
echo "PRIMARY key:". $object->primary_key. " <br> ";
echo "NOT null:". $object->not_null. " <br> ";
echo "field type:". $object->type. " <br> ";
echo "Field max Length:". $object->max_length. " <br> ";
?>
This also meets the same requirements as the previous example.