Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get number of fields in mysql table

Tags:

sql

php

mysql

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?

like image 457
Paul Avatar asked Dec 13 '25 13:12

Paul


1 Answers

SELECT COUNT(*) totalColumns
FROM   INFORMATION_SCHEMA.COLUMNS
WHERE  table_name = 'table1' AND 
       TABLE_SCHEMA = 'databaseName'
  • SQLFiddle Demo
like image 122
John Woo Avatar answered Dec 15 '25 04:12

John Woo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!