Sandesh Sandesh - 7 months ago 55
MySQL Question

php mysql and unicode

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: "समाचार".


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

See the manual entry for set_charset here:

You can also run an initial query SET NAMES utf8.