Sometimes it is advantageous to have information about the columns of a table in the database.
If all you need is the SQL, copy the box bellow and use it in your favorite program.
SELECT `COLUMN_NAME`, `DATA_TYPE`, `COLUMN_DEFAULT`, `COLUMN_TYPE`
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA` = ? AND `TABLE_NAME` = ?";
Here is a nice example function written in PHP that uses PDO to read the table columns and return a formatted array with the data.
Continue reading “Get a MySQL Table Row-names and Types using PHP PDO”