Quickly learn how to use PHP to obtain field data types. For beginners, they must learn how to use various mysql_field_type () functions to obtain the data types of Fields. the syntax format of this function is as follows. 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.
Use the mysql_field_type () function to obtain the data type of a field. the syntax format of this function is as follows ....