How to get the mysql table columns data type?

krishnakumar picture krishnakumar · Aug 1, 2009 · Viewed 178.8k times · Source

I want to get the column data type of a mysql table.

Thought I could use MYSQLFIELD structure but it was enumerated field types.

Then I tried with mysql_real_query()

The error which i am getting is query was empty

How do I get the column data type?

Answer

brian-brazil picture brian-brazil · Aug 1, 2009

You can use the information_schema columns table:

SELECT DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE table_name = 'tbl_name' AND COLUMN_NAME = 'col_name';