Mysql insert encoding problem

I am trying to insert a Utf-8 string into a cell with utf8_general_ci collation

My code is:

  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> ... print mb_detect_encoding($name); $query = "INSERT INTO items SET name='$name', type='$type'"; print $query; mysql_set_charset('utf8'); // also doesn't help $result0 = mysql_query("SET CHARACTER SET utf8") or die(mysql_error()); // I've added this line, but it doesn't solve the issue $result01 = mysql_query('SET NAMES utf8') or die("set character ".mysql_error()); // still nothing $result = mysql_query($query) or die(mysql_error()); 

What I see in the html output:

 UTF-8 INSERT INTO waypoints SET name='ČAS', type='ts' 

What I see in the database, as name in the inserted row:

 ?AS 

Now my row is utf-8, my table and cell are utf-8 .. why is the encoding incorrect?

+4
source share
1 answer

Ok guys, thanks everyone for the help, it looks like I solved the problem:

  mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $link); 

immediately after creating the connection

(especially @Bartdude for the article that gave me a hint)

+2
source

Source: https://habr.com/ru/post/1489699/


All Articles