For a beginner, they must learn how to use various types of resources flexibly.
The mysql_field_type () function obtains the Data Type of a field. The syntax format of this function is as follows.
String mysql_field_type (resource $ result, int $ field_offset)
The mysql_field_type () function is similar to the mysql_field_name () function, but the mysql_field_type () function returns the Data Type of the field. Its parameters 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.
The sample code for using the mysql_field_type () function is as follows:
Code 23-12 cd-rom codes chapter 23.3mysql _ field_type.php
- <? 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_type ($ result, 0 );
- // Data type of the first field
- Echo "<br> ";
- Echo mysql_field_type ($ result, 1 );
- // Data type of the Second Field
- Echo "<br> ";
- Echo mysql_field_type ($ result, 2 );
- // Data type of the Third Field
- Mysql_free_result ($ result );
- Mysql_close ();
- ?>
After the preceding code is executed, the Data Types of the first three fields in the table "employee" are output.