Reputation: 15930
I'm accessing a MySQL database using PDO in PHP. Say I have a table with a column of type CHAR(30), or INT(5):
30
and 5
) from a PHP script using PDO, that is not database-specific?Upvotes: 1
Views: 2435
Reputation: 211560
This informations should be available in the information_schema.columns
table:
SELECT CHARACTER_MAXIMUM_LENGTH, NUMERIC_PRECISION, NUMERIC_SCALE FROM information_schema.columns WHERE TABLE_NAME = 'your_table_name'
There's different columns for string lengths (CHARACTER_MAXIMUM_LENGTH
) and numerical lengths (NUMERIC_PRECISION
).
Update:
To work-around a limitation/bug of MySQL where the lengths are not always reported correctly, it might be necessary to parse the definitions themselves and extract the number within brackets.
Upvotes: 2