PHP + PDO/MySQL: how to automatically query to find out VARCHAR field lengths?

mysql, pdo, php

Solution

Read it from INFORMATION_SCHEMA COLUMNS

Problem

is there a way to use PHP+PDO to query a MySQL database and find out the column widths of some VARCHAR fields? I don't want to hardcode them into my PHP file if possible. (purpose: determine maximum lengths of strings to be either inserted into these columns, or compared against existing data in the columns.)

Original source