mysql_num_fields Functions to get number of fields returned in a query
This old MySQL extension was deprecated in PHP 5.5.0 and was removed in PHP 7
WE can get the number of fields in our executed query by using mysql_num_fields function. This function returns the number of fields returned by the query.
Use mysqli_num_fields() in place of mysql_num_fields(). Here is an example
The above code will print 4 as we have 4 columns in our student table.
Now let us change the query a bit ( only query part is changed and all other parts remain same )
Now the output of the print command will display 2 ( not 4 ). So the function mysql_num_fields function returns the number of columns returned by the query.
Read how mysql_num_fields() is along with mysql_field_name function is used to display all column names of a table. Download sql dump of student table Subscribe to our YouTube Channel here
This article is written by plus2net.com team.
https://www.plus2net.com
![]() ![]() | ||||||||
| ||||||||