September 16th, 2013, 05:51 PM
Max length of Column in SQL Table
My application is essentially I wast to read a column figure out the maximum length in order to determine what field type to use in an API for an ecomm platform.
According to the stuff I read, the code should look something like this
$query="SELECT max(length(ITATR1)) from testtable5";
I get this:
mysqli_result Object ( [current_field] => 0 [field_count] => 1 [lengths] => [num_rows] => 1 [type] => 0 )
Any idea what I may be messing up to not return a length?
September 16th, 2013, 06:00 PM
You forgot to actually fetch the result.
The LENGTH() function also makes no sense in this context, because it returns the number of bytes, not the number of characters. In a modern multi-byte encodings like UTF-8, this will yield nonsense results. What you want is CHAR_LENGTH().