1

I am trying to insert unicode content on phpmyadmin in xampp. I set both the collation for my database and for my table to utf8. But whenever I am trying to insert the unicode data(i.e. Nepali or hindi fonts), the data is stored like this: The highlighted text.

The data is displayed correctly. As I have set charset on meta tag to utf-8. The main problem is I want to store the data as it is.

Is there any way to store the data as it is? The data actually is: "समाचार".

10
  • Show you code....... Commented Aug 3, 2016 at 5:30
  • INSERT INTO [table_name] SET added_date = now(), added_by = 1, category_name = 'खेलकुद', category_status = '1', show_in_menu = '1' This is my insert code. I am using mysqli. Commented Aug 3, 2016 at 5:34
  • Try going into phpMyAdmin and clicking the structure tab for the table then find the "collation" dropdown box for the field you'd like to store the utf-8 characters in, then change it to utf8_unicode_ci. Then try inserting the data. Commented Aug 3, 2016 at 5:35
  • @Ultimater I already did that as well. Both the collation to utf8_unicode_ci as well. But did not work. Commented Aug 3, 2016 at 5:37
  • Works for me, here's a SQL dump: pastie.org/10927743 Commented Aug 3, 2016 at 5:41

1 Answer 1

1

You need to set the charset on the adapter so it doesn't corrupt the characters before trying to insert them. Since you're using MySQLi as your database adapter, you'd be looking for one of the following solutions:

// Procedural style mysqli_set_charset($link, "utf8"); // Object oriented style $mysqli->set_charset("utf8"); 

See the manual entry for set_charset here: http://php.net/manual/en/mysqli.set-charset.php


You can also run an initial query SET NAMES utf8.

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

1 Comment

Yes its the correct way. Or you can do something like this: $connectionVar->query("SET NAMES urf8");

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.