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


5 Replies to “Unicode in PHP and MySql”

  1. 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.

    1. 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.

    1. 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,

  2. 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,

Comments are closed.