Storing weird characters in MySQL

Discussion in 'PHP' started by Tipem, Jul 27, 2008.

  1. #1
    [​IMG]

    What kind of collation will I need on a TEXT column in MySQL to store those values without them going to ????? s?
     
    Tipem, Jul 27, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    UTF-8 should work just fine. Make sure to specify the same charset when OUTPUTTING them later on.

    
    header('Content-Type: text/html; charset=uft-8');
    
    PHP:
    If you have a charset specified in a HTML <meta> tag, make sure to change that too.

    EDIT:

    If that still doesn't work, try running this query before running any other one:
    
    mysql_query('SET NAMES utf-8');
    
    PHP:
     
    nico_swd, Jul 27, 2008 IP
  3. Tipem

    Tipem Active Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    The charset on my page is already utf-8. :)

    It has something more to do with MySQL rather than the actual output of the page. MySQL will replace several of those characters in my previous post (with the exception of straight letters and numbers, @ symbols, you know - the common ones) with ????. When the data is sent back out, it displays these ????s instead of the true characters.

    I've searched through the collation drop down in phpMyAdmin for the MySQL column storing this string and unfortunately there's no straight "uft-8" collation, but instead there's like 50 variations of unicode. I've tried two (utf8_unicode_ci and uft_8bin) but neither of them have worked (nor the default latin_swedish collation).

    Any ideas? Thanks for your help.

    EDIT to your edit:

    Mysql says: #1115 - Unknown character set: 'utf'
     
    Tipem, Jul 27, 2008 IP
  4. php-lover

    php-lover Active Member

    Messages:
    261
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    58
    #4
    try serialize your string before store to database

    serialize()
     
    php-lover, Jul 27, 2008 IP
  5. Tipem

    Tipem Active Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #5
    I'm afraid that it's still doing the same thing -- replacing complicated characters with question marks.

    Serialize didn't help... :( Whenever I've changed my pages from iso-8859-1 to utf-8, it messes up the characters. The best kind of page encoding for these characters seems to be iso-8859-1. However, these kinds of characters will never be outputted on the page -- they will just be stored in the database. Unfortunately there is no "iso-8859-1" collation for MySQL, what could I try instead?

    Still trying to figure out how to store it in the db...
     
    Tipem, Jul 27, 2008 IP
  6. Tipem

    Tipem Active Member

    Messages:
    93
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #6
    SOLVED: Encode it to base64 and store those characters.
     
    Tipem, Jul 27, 2008 IP