Set character set?

Discussion in 'MySQL' started by Triexa, Nov 29, 2006.

  1. #1
    I am having problems with my character set - and as a result, certain characters get converted. I changed the column collation to "utf8_general_ci", but it didn't work.

    When I use phpMyAdmin to edit the field, it updates properly, but when done from PHP it doesn't work (but if I echo the value right before insert, it shows up properly)

    What do I need to do? I was told I need to change 'character_set_client', but I don't even know where/how to edit it.

    Any assistance?
     
    Triexa, Nov 29, 2006 IP
  2. Antonio

    Antonio Well-Known Member

    Messages:
    1,504
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    155
    #2
    For database
    ALTER DATABASE `database` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
    Code (markup):
    For table
    ALTER TABLE `table` DEFAULT CHARACTER SET utf8; 
    Code (markup):
    Run it in SQL
     
    Antonio, Nov 29, 2006 IP
  3. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #3
    I did the alter table, but still when I update a row it doesn't work. What I am entering was given to me by someone:
    Quali post ritenete più interessanti?

    When I echo it right before the query, it shows up properly. When I go back and fetch it, I get:
    Quali post ritenete più interessanti?
     
    Triexa, Nov 29, 2006 IP
  4. Antonio

    Antonio Well-Known Member

    Messages:
    1,504
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    155
    #4
    What's the version of phpmyadmin?
    Maybe you need a utf-8 connection.
     
    Antonio, Nov 29, 2006 IP
  5. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #5

    well how do I make a utf-8 connection then? phpMyAdmin is 2.9.0.2
     
    Triexa, Nov 29, 2006 IP
  6. Antonio

    Antonio Well-Known Member

    Messages:
    1,504
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    155
    #6
    For example, it is utf-8 connection for wordpress
    
    		$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    		$this->query("SET NAMES 'utf8'");
    
    Code (markup):
    Your phpmyadmin can set certain characters for tables in structure.

    Another way you can ask your host set the default mysql collation to utf-8.
     
    Antonio, Nov 29, 2006 IP
  7. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #7

    I have access but I don't know how... how do I set the default collation?
     
    Triexa, Nov 30, 2006 IP
  8. Antonio

    Antonio Well-Known Member

    Messages:
    1,504
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    155
    #8
    If you are the hoster you can set it in mysql server. (mysql.ini)
     
    Antonio, Nov 30, 2006 IP
  9. Triexa

    Triexa Active Member

    Messages:
    580
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #9
    ooh I was trying to edit my.cnf which seemed to have no effect. When I do "whereis mysql.ini", i get a number of locations. How do I know which one is the one to use?
     
    Triexa, Nov 30, 2006 IP
  10. Antonio

    Antonio Well-Known Member

    Messages:
    1,504
    Likes Received:
    128
    Best Answers:
    0
    Trophy Points:
    155
    #10
    It is in the root of mysql folder. If you can't find it just do a search. It is just called mysql.ini.
     
    Antonio, Nov 30, 2006 IP
  11. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #11
    Use
    
    mysql_query("SET NAMES 'utf8'");
    
    PHP:
     
    wmtips, Nov 30, 2006 IP