Skip to content
Advertisement

MySQL select column length in php (below PHP7)

How do I get the actual max length of a specified column in php (prior to PHP7)?

For instance, this table:

id – int(11) name – string(20)

I want in php to select the maximum number of characters that a field can have, like

SELECT length(name) from table1

and it should then return 20 (since it’s the maximum number of characters for that field).

Advertisement

Answer

You should use mysql_field_len

http://php.net/manual/en/function.mysql-field-len.php

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement