1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Rep Power

    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

    PHP Code:

    ="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?
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power
    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().
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo