7) database information functions (2 ):
1. mysql_fetch_field ()
Format: object mysql_fetch_field (int query, int [field_offset]);
Returns an object, that is, a hash table marked:
Table: table name
Name: Field name
Max_length: maximum length of the field
Not_null: If the field is not null, 1 is returned; otherwise, 0 is returned.
Primary_key: If the field is primary key, 1 is returned; otherwise, 0 is returned.
Unique_key: If the field is unique key, 1 is returned; otherwise, 0 is returned.
Multiple_key: If the field is not a unique key, 1 is returned; otherwise, 0 is returned.
Numeric: If the field is numeric, 1 is returned; otherwise, 0 is returned.
Blob: If the field is blob, 1 is returned; otherwise, 0 is returned.
Type: field type
Unsigned: If the field is unsigned, 1 is returned; otherwise, 0 is returned.
Zerofill: If the field is zero filled, 1 is returned; otherwise, 0 is returned.
Reference format: Object name-> subscript name
You can use this function to obtain the table name, field name, and type .......
Example:
$ Query = mysql_query ($ SQL, $ connect );
While ($ object = mysql_fetch_field ($ query ))
{
Echo "table name:". $ object-> table ."
";
Echo "field name:". $ object-> name ."
";
Echo "primary key:". $ object-> primary_key ."
";
Echo "not null:". $ object-> not_null ."
";
Echo "field type:". $ object-> type ."
";
Echo "field max length:". $ object-> max_length ."
";
}
?>
Note: the hash table starts with 0 coordinates, that is, the first field is 0 items in the hash table.
If you want to directly obtain the information of the third field in the hash table, the format is as follows:
$ Query = mysql_query ($ SQL, $ connect );
$ Object = mysql_fetch_field ($ query, 2 );
Echo "table name:". $ object-> table ."
";
Echo "field name:". $ object-> name ."
";
Echo "primary key:". $ object-> primary_key ."
";
Echo "not null:". $ object-> not_null ."
";
Echo "field type:". $ object-> type ."
";
Echo "field max length:". $ object-> max_length ."
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.