Database-related operations are always encountered during WEB development. As a beginner, this must be mastered. The following is a detailed analysis.
In addition to the field name, data type, and length, a field also has some other attributes, such as whether it is a primary key, whether it is a foreign key, and whether it is allowed to be empty. PHP can use the mysql_field_flags () function to obtain field attributes. The syntax format of this function is as follows:
String mysql_field_flags (resource $ result, int $ field_offset)
The parameters involved in the preceding syntax are described as follows:
L result: the result set returned after the mysql_query () function is executed.
L field_offset: the offset of a field. The start value is zero.
Sample Code for retrieving field attributes using PHP of mysql_field_flags () function is as follows:
- <? Php
- $ Connection = mysql_connect ("localhost ",
"Root", "root") or die ("failed to connect to the server ");
- Mysql_select_db ("sunyang", $ connection)
Or die ("failed to select database ");
- $ Query = "select * from employee ";
- $ Result = mysql_query ($ query) or die
("Failed to query data"); // execute the query
- Echo mysql_field_flags ($ result, 0 );
// Attributes of the first field
- Echo "<br> ";
- Echo mysql_field_flags ($ result, 1 );
// Attributes of the Second Field
- Echo "<br> ";
- Echo mysql_field_flags ($ result, 2 );
// Attributes of the Third Field
- Mysql_free_result ($ result );
- Mysql_close ();
- ?>
The above is the related PHP skills for getting field attributes.