Oriesok Vlassky
Oriesok Vlassky

Reputation: 797

Mysql insert encoding issue

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

My code:

 <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 string is utf-8, my table and cell is utf-8 .. why the wrong encoding?

Upvotes: 4

Views: 3279

Answers (1)

Oriesok Vlassky
Oriesok Vlassky

Reputation: 797

Ok guys, thank you all for help, it looks like I've solved the issue with:

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

right after creating the connection

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

Upvotes: 3

Related Questions