Paul Paul - 5 months ago 10
PHP Question

Get number of fields in mysql table

How can I get number of fields(—Āolumns) in mysql table with PHP or just some kind of mysql query? Is there a way to do this without

SELECT * FROM table_name
and
mysql_num_fields()
? Maybe there is a way with one mysql query?

Answer
SELECT COUNT(*) totalColumns
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  table_name = 'table1' AND 
       TABLE_SCHEMA = 'databaseName'