Through
The mysql_num_fields () function counts the number of all fields in the table to be queried. The syntax format of this function is as follows:
Int mysql_num_fields (resource $ result)
The result parameter is the result set returned after the mysql_query () function is executed. Sample Code for obtaining the number of fields in PHP using the mysql_num_fields () 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 ("Data Query failed"); // execute the query
- Echo mysql_num_fields ($ result );
// Number of output Fields
- Mysql_free_result ($ result );
- Mysql_close ();
- ?>
The above describes how to obtain the number of fields in PHP.