As a qualified
When designing a database, because each field represents different data meanings, the length of each field will not be exactly the same. In PHP, you can use the mysql_field_len () function to obtain the Field Length in PHP. The syntax format of this function is as follows:
Int mysql_field_len (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 obtaining the field length using PHP of mysql_field_len () 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_len ($ result, 0 );
// The length of the first field
- Echo mysql_field_len ($ result, 1 );
// The length of the Second Field
- Echo mysql_field_len ($ result, 2 );
// The length of the Third Field
- Echo mysql_field_len ($ result, 3 );
// The length of the fourth field
- Mysql_free_result ($ result );
- Mysql_close ();
- ?>
The above describes how to obtain the length of a field in PHP.