For example :
tbl_ifo id | name | age | gender ---------------------------- 1 | John | 15 | Male 2 | Maria | 18 | Female 3 | Steph | 19 | Female
this query may help you
SELECT COUNT(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_CATALOG = 'database' AND TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'tbl_ifo'
Simply use mysql_fetch_assoc and count the array using count() function