Unicode in PHP and MySql

While I was working with Nepali Unicode in PHP and MySql, I found difficulty in inserting Nepali into database. I made some explorations and found a way to deal with this.

There are some basic things you need to be careful when working with Unicode, especially with database.

The database itself should be encoded in UTF-8 format and whatever is the method to access that particular database, The programming language should be aware that the database is UTF-8 enocded.

The field to store Unicode text should also be changed to<Strong>utf8_general_ci</strong> under collations.

1. How to create database UTF-8 encoded.

a. Start Phpmyadmin, Then enter the database name

Under MySql Connection Collation select utf8_general_ci then hit create.

See the figure below

Database Encode
Database Encode


Samundra Shrestha

I work as fullstack developer. Having spent more than 5 years in the web development technologies, I aspire to create an environment where we can share, learn and grow together.

5 thoughts on “Unicode in PHP and MySql

  • August 27, 2010 at 9:42 AM

    i need to keep the nepali unicodes in a file and handling it..any idea plz..email me i will be happy if u solve this.
    Chiranjibi Sitaula
    Central Department of Computer Science and Information Technology, T.U, Kirtipur.

    • August 27, 2010 at 5:01 PM

      Dear Chiranjibi,

      Thanks for comment.

      Regarding your question>To store nepali unicode in a file first you have to set the file format to UTF8. Most of the programming langauges nowadays, have options to handle UTF8 file formats. I could have been more helpful to you if you could have provided more information like programming language you are using for file handling. Hope you got some idea. Good luck.

  • July 7, 2010 at 7:02 AM

    not working for
    odbc_exec($connection,’SET NAMES utf8′);

    • July 10, 2010 at 9:03 AM

      Dear Samsung_0101,

      I haven’t tested this method with odbc_exec. Have you already set your database to store Unicode data, if not that might be your problem. I couldn’t get your problem exactly, Are you having problem in storing data or you mean the code is not working at all.

      I suggest you to first prepare database to store unicode data. This is done during the creation of database. Anyway I will check this and confirm as well.

      Thanks for comment and pointing out the odbc_exec() function.

      with best regards,

  • July 7, 2010 at 6:23 AM

    this Unicode in PHP and MySql…

    Its clean and simple ,,
    i am now working with ODBC (MS Access) ,
    its not working with , ‘set names utf8’;

    So how to insert or update unicode values into Access database using odbc???

    Thank you,


Leave a Reply

Your email address will not be published. Required fields are marked *