promotion image of download ymail app
Anonymous asked in Computers & InternetProgramming & Design · 9 years ago

php mysql insert UTF-8?


Im just so frustrated because Iv searched for answer to this for over an hour and Im stuck!

I need to execute mysql query through php.. ok it's easy. I have data that requires UTF-8 for characters like "ā", "ņ" etc. When their stored in mysql database they are changed to "?" question marks. I just dont know what to do anymore because I tried exeuting

mysql_query("SET NAMES 'utf8'");

mysql_query("SET CHARACTER SET utf8");

before query and after connectiong to database. My tables and fields and everything in Mysql is set to utf8_general_ci.

I just can't find the solution, please help!


and the .php files are also saved in UTF-8

Update 2:

Yes I have the database in UTF-8, because from phpmyadmin I can add thous symbols but when I try through php they show up as "?".

Tryed removing all thous SET NAMES UTF-8 etc, but still nothing..

Update 3:

Ok Solved the problem with clear head today. I had two mysql_query("SET NAMES 'utf8'"); one on the connect function and other on select. I think they kind a conflicted and now I have only mysql_query("SET NAMES 'utf8'"); at the connect and everything is working.

2 Answers

  • 9 years ago
    Favorite Answer

    i had and still have some problems with mysql and some utf-8 charchters ,

    anyways , its enough to set the collation of the table to utf8_general_ci

    and remove those 2 lines :

    mysql_query("SET NAMES 'utf8'");

    mysql_query("SET CHARACTER SET utf8");

    inserted characters wont be turned into question marks ,and might also not be understandable through phpmyadmin or mysql command line client , but when you retrieve (select) the data from mysql through php and view it , it would be shown as it was inserted . like this (for example) : 'ņ'.

    • Commenter avatarLogin to reply the answers
  • 9 years ago

    Have you created the database in UTF8?

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.