0

I have a page with utf-8 encodin. Mysql is set to utf8_general_ci. Here is the query:

 mysql_query("SET CHARACTER SET utf8_general_ci");

               $query = "INSERT INTO newsbox VALUES ('null', '$zaglavie', '$nom_file_big', '$den', '$mesec', '$godina', '$zaglavie2', '$text', '$zaglavie3')";
                $result = mysql_query($query) or die(mysql_error()); 

and cyrillic input text is inserted like ?????. What could be the problem.

2 Answers 2

6

What I tend to find solves things a lot is;

mysql_query("SET NAMES 'utf8'");

Before any queries are performed.

The documentation recommends that you use mysql_set_charset but I often see that function missing.

if( function_exists('mysql_set_charset') ){
    mysql_set_charset('utf8', $db_con);
}else{
    mysql_query("SET NAMES 'utf8'", $db_con);
}
2
  • 1
    wow this worked for me! any idea why I didn't need to do this in the past? Commented Jun 11, 2013 at 14:49
  • I suppose it depends on the settings of your past environments - perhaps you got lucky. Commented Jun 11, 2013 at 21:04
1

I'm not sure if the mysql_query("SET ..") works as expected. Try setting the character set with mysql_set_charset(). Are you sure the text is inserted like that? If you're using the CLI mysql client with a wrong character set, display output may be faulty as well (that probably goes for retrieval via mysql_fetch_*() as well).

1
  • I am using my scripts for years and thats the first time I have such a problem :( Commented Jan 20, 2011 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.