4

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?

7
  • How do you "see it in the database"? Maybe it is just an encoding problem of your tool. Commented Jul 4, 2013 at 12:09
  • How about mysql_set_charset() ? Commented Jul 4, 2013 at 12:09
  • phpmyadmin.. anyway I've tried select and print, it is stil ?AS Commented Jul 4, 2013 at 12:09
  • 1
    You see wrong encoding in html, but what is html encoding, is it UTF-8 ? Commented Jul 4, 2013 at 12:10
  • 1
    Here's my reference article when it comes to UTF-8 in webapps : kunststube.net/frontback Commented Jul 4, 2013 at 12:12

1 Answer 1

3

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)

Sign up to request clarification or add additional context in comments.

Comments

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.