SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Which UTF8 collation should I use for this?

    I'm trying to store strings that may include special characters. Presuming the gurus under the hood here have it working, I'd like to be able to store and retrieve characters similar to the following:

    ɤ

    My meta tag:
    Code:
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    ...doesn't specify which UTF-8 collation to use, so I left it as default "utf8_general_ci"....but I'm getting random odd characters.

    I figure it's got to be one of the 3 below -- and I've tried them all on the table, but wondered if maybe that corrupted the data by switching it with data already inside. (No worries, its just filler data for dev purposes.)

    Code:
    utf_bin
    utf8_general_ci
    utf8_unicode_ci

    Which collation should I use to not have problems with those types of characters?

    Thanks for your wisdom!

  2. #2
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm... running this query against the database (SHOW VARIABLES LIKE 'character_set%') I find the following:

    Code:
    character_set_client 	utf8
    character_set_connection 	utf8
    character_set_database 	utf8
    character_set_filesystem 	binary
    character_set_results 	utf8
    character_set_server 	latin1
    character_set_system 	utf8
    character_sets_dir 	/data/mysql/prante/share/mysql/charsets/
    Another post suggested to use mysql_query("SET NAMES 'utf8'"); and that it solved the problem. That's cool and I'll give it a try -- and if it works for me, is there a way to achieve it through phpMyAdmin?

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,073
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    It's best to use mysql_set_charset() rather then mysql_query("SET NAMES 'utf8'") to set the default charset for the connection to the database. It should be used after you established the connection to the database but before you start running any queries against the database
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Addict cranjled's Avatar
    Join Date
    Apr 2004
    Location
    ny
    Posts
    382
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you -- if you don't mind a follow-up: Are there certain benefits to using utf8_general_ci over utf8_unicode_ci (or vice versa) for the database encoding?


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
  •