Mysql php request encoding problem

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

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 the input text with the Cyrillic alphabet is inserted as ?????. What could be the problem.

0
source share
2 answers

I am not sure if mysql_query ("SET ..") works as expected. Try setting the character set with mysql_set_charset (). Are you sure the text is inserted like this? If you use the mysql CLI client with the wrong character set, the display output may also be faulty (this is probably suitable for retrieval via mysql_fetch _ * ()).

+1
source

What I usually look for solves a lot:

 mysql_query("SET NAMES 'utf8'"); 

Before performing any queries.

The documentation recommends using mysql_set_charset , but I often see that the function is missing.

 if( function_exists('mysql_set_charset') ){ mysql_set_charset('utf8', $db_con); }else{ mysql_query("SET NAMES 'utf8'", $db_con); } 
+6
source

All Articles