SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    char(x) question regarding db interpretation

    I was looking in the MySQL 5 Manual and ran across this note:
    ------------------------------------------------------------
    Character data types (CHAR, VARCHAR, TEXT) can include CHARACTER SET and COLLATE attributes to specify the character set and collation for the column. For details, see Chapter 10, Character Set Support. CHARSET is a synonym for CHARACTER SET. Example:

    CREATE TABLE t (c CHAR(20) CHARACTER SET utf8 COLLATE utf8_bin);

    MySQL 5.0 interprets length specifications in character column definitions in characters. (Versions before MySQL 4.1 interpreted them in bytes.)
    --------------------------------------------------------------
    So does that mean that if I want to specify a varchar(20) in MySQL 4.0.24 that the string is going to be limited to 20 bytes? How long would that be?

    still_waiting

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    it depends on the server's character set. if you use a character set like iso-8859-1, then there's one byte per character. if you're using a multi-byte character set like utf-8 or utf-16, it could be as many as 4 bytes per character.

  3. #3
    SitePoint Zealot
    Join Date
    Dec 2005
    Posts
    121
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, let me see if I understand what you are saying.
    If the server (db server? webserver?) uses utf-8 or 16 I could have a problem in mysql 4.0.24 because because with a varchar(20) I could be limited to as few as 5 characters? The app I am building will be hosted in a shared environment so how am going to find out what character set is being used or is that something I can specify?

    Just a newbie trying to learn.
    still-waiting

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    yes, but most basic rate web hosts do not run utf8 on mysql 4.0 because PHP does not have native support for multibyte character sets.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •