I wrote code to do this in Zend_Db_Adapter_Mysqli ::describeTable() .
It handles varchar, char, decimal, float and all MySQL data types.
I will not post the code here due to the StackOverflow CC-wiki license policy, but follow this link.
mysql_fetch_field() only reports data types for query result sets, not tables to save.
INFORMATION_SCHEMA is another option, but its early implementation in MySQL has incredibly low performance, which makes it difficult to use in a web application that requires fast response times. Some changes in MySQL 5.1.23 tried to improve performance, but some people still report problems.
source share