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

Is there a way to use PHP + PDO to query a MySQL database and find out the column widths of some VARCHAR fields? I do not want to hardcode them into my PHP file, if possible.

(goal: determine the maximum row lengths that you need to either insert into these columns or compare with existing data in the columns.)

+3
source share
4 answers
+4
source

information_schema. columns . , , "CHARACTER_MAXIMUM_LENGTH".

+5

Run this query: DESCRIBE table_name', where table_name is the name of the table in which you are looking for information. He will return what you seek.

+1
source

Select CHARACTER_MAXIMUM_LENGTH from INFORMATION_SCHEMA.COLUMNS, where COLUMN_NAME = 'yourcolumn' and TABLE_NAME = 'yourtable';

+1
source

Source: https://habr.com/ru/post/1710862/


All Articles