Learning Is Fun

Talks on Web Technology and Better Product Development

PHP – MySQL: Unicode solution to Chinese, Russian or any language

October13

Hey Guys,

I am a Freelance Web Developer and my main tools are PHP & MySQL. Few days ago, I got a Chinese project where I had to develop a Real Estate site in Chinese language. You know we often build websites in English and Databases are in English too. So, the default configuration in MySQL works fine everytime.

But when it comes a language other than English, many people do not know what to do. Well. When I started the project, I did not even know that the default MySQL settings will not work for the Chinese language. So, I started searching for a stable solution where my program will support any language for adding, updating and searching data from the MySQL database.

And Yeah.
I found it!

OK.

Let us see the solution now.
It is very very simple.

Step One: SET THE CHARSET TO UTF-8 IN THE HEAD SECTION

First of all, the browser needs to know that you are going to display or use Unicode in this page. So, go to your <HEAD></HEAD> section and set the charset to utf-8. So, the browser will be able to show the Unicode text without any error and smoothly. You can also copy and paste the line below:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Step Two: CREATING THE DATABASE

When you create your (a) Database and (b) any Table in the database, set the Collation of both of them to utf8_unicode_ci and you know it is very easy if you are using phpMyAdmin.

Step Three: DATABASE INITIALIZATION

When you initialize the database connection, please add the “extra lines”

<?php
	define('HOSTNAME', 'localhost');
	define('USERNAME', 'database_user_name');
	define('PASSWORD', 'database_password');
	define('DATABASE', 'database_name');
	$dbLink = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
	mysql_query("SET character_set_results=utf8", $dbLink);
	mb_language('uni');
	mb_internal_encoding('UTF-8');
	mysql_select_db(DATABASE, $dbLink);
	mysql_query("set names 'utf8'",$dbLink);
?>

But why are you adding the extra lines? Because you are letting the database know what kind of input you are going to work with soon.

Step Four: INSERTING INPUTS/DATA IN THE DATABASE

<?php
	mysql_query("SET character_set_client=utf8", $dbLink);
	mysql_query("SET character_set_connection=utf8", $dbLink);
	$sql_query = "INSERT INTO
	TABLE_NAME(field_name_one, field_name_two)
	VALUES('field_value_one', 'field_value_two')";
	mysql_query($sql_query, $dbLink);
?>

Why are you adding the first two lines for? Because the database should know what kind of data is going to be stored.

Step Five: UPDATING INPUTS/DATA IN THE DATABASE

<?php
	mysql_query("SET character_set_client=utf8", $dbLink);
	mysql_query("SET character_set_connection=utf8", $dbLink);
	$sql_query = "UPDATE TABLE_NAME
	SET field_name_one='field_value_one', field_name_two='field_value_two'
	WHERE id='$id'; ";
	mysql_query($sql_query, $dbLink);
?>

So, you are adding the extra two lines before you run your query string as you are playing with Unicode.

Step Six: SEARCHING DATA FROM THE DATABASE

<?php
	mysql_query("SET character_set_results=utf8", $dbLink);
	$sql_query = "SELECT * FROM TABLE_NAME WHERE id='$id'; ";
	$dbResult = mysql_query( $sql_query, $dbLink);
?>

Adding the one extra line every time you search your Unicode data is enough.

OKKK.
You are done. This should work smoothly for handling your data in any language does not matter it is Bangla (my mother tongue), Hindi, Chinese, French, German, Spanish, Russian, Arabian (Arabic), Urdu, or any other language.

And do not forget to leave a comment if you have any. Because I need to update the post in case required.

Thanks for reading and please check if it works for you.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
posted under MySQL, PHP
128 Comments to

“PHP – MySQL: Unicode solution to Chinese, Russian or any language”

  1. On November 2nd, 2008 at 1:07 pm Jooma Says:

    I’m new to php world. Everytime that I got the result from my query was ????? because those text stored inside my DB were Unicode. This article saved my day. Thank you.

  2. On November 2nd, 2008 at 1:12 pm admin Says:

    I know.
    It happened with me too.

    I am happy to know that it helped you.
    :)

  3. On November 2nd, 2008 at 6:51 pm Smokey Says:

    What am I doing wrong. I have a MySQL database with Russian/Cyrillic words. They look fine in phpmyadmin, but on the utf-8 encoded html page I got ?????. After following your tutorial I got мобРinstead.

    Database charset is set to utf8 and collation is set to utf8_unicode_bin, collation for the table is utf8_unicode_bin, and the same for the column.

    I work with Smarty templates and the database call looks now like this:

    $db = DB::connect(“mysql://$dbuser:$dbpass@$dbhost/$dbname”);
    mysql_query(‘SET character_set_results=utf8′);
    mb_language(‘uni’);
    mb_internal_encoding(‘UTF-8′);
    mysql_query(“SET NAMES ‘utf8′”);

    I need to get this working for Monday… and am pulling my hair right now. Any help is really appreciated. Thanks

  4. On November 2nd, 2008 at 11:56 pm admin Says:

    @ Smokey

    You are using ‘utf8_unicode_bin’.

    My article suggests to use only ‘utf8_unicode_bin’.
    Can you try ‘utf8-unicode_ci’ in database and table creation?
    And please follow the article exactly as described because this is a sensitive issue.

    Thank you.

  5. On November 3rd, 2008 at 12:35 am admin Says:

    @ Smokey

    Make sure the followings have ‘utf8-unicode_ci’ attribute:
    1. Database
    2. Tables
    3. Fields in the table

    All of the three need to have ‘utf8-unicode_ci’ attribute. OK?

  6. On November 3rd, 2008 at 8:54 am Smokey Says:

    Yes, I have them already set to utf8_unicode_ci. Any other suggestions??

  7. On November 3rd, 2008 at 8:58 am admin Says:

    Can you zip your database and upload it somewhere?

    By the way,
    I can take a look by tomorrow since I am very busy today.

  8. On November 3rd, 2008 at 11:57 pm Smokey Says:

    Ok, after hours of hair pulling I figured it finally out. In my PHP smarty code I had the htmlentities set. I removed the smarty code $smarty->register_modifier(“variable”,”htmlentities”); and everything worked fine. I will read up on this, but here is a post that mentions this problem. Here is the php documentation http://us2.php.net/htmlentities and another article about it http://annevankesteren.nl/2004/05/unicode-support

    PS: could you please remove my email from my last post… thanks

  9. On November 4th, 2008 at 12:07 am Smokey Says:

    … I forgot, as mentioned in your post. I also had to set mysql_query(mysql_query(‘SET character_set_results=utf8′); after initializing the database connection

  10. On November 4th, 2008 at 12:30 am admin Says:

    @ Smokey

    I am happy to hear that your problem has been solved.
    Great!
    And I deleted your message that one you wanted.

  11. On November 7th, 2008 at 7:51 pm YeGullelew Says:

    I do appreciate the effort you make to teach us in an easy way. I am in the process of developing an application that utilizes unicode and it is real good place to start it.
    I promise to let you know any difficulties I got, the solution I make, things I found important …and even more to post to this site.
    Thank you.

  12. On November 7th, 2008 at 10:32 pm admin Says:

    @ YeGullelew

    I appreciate your positive approach too.

  13. On November 23rd, 2008 at 10:02 am Yohan Launay - ConceptSL Says:

    Excellent post.

    Many thanks

    - Yohan

  14. On November 24th, 2008 at 12:47 pm philomena simonenko Says:

    Thank you so much for this tutorial. It is very simple and easy to follow and you saved my bacon.
    Your a genius, thank you

  15. On November 30th, 2008 at 3:19 pm Fencer Says:

    hey big thx for you i have had to implement a page with 3 different languages. This tutorial saved me a lot of time a stress it works really great

  16. On December 22nd, 2008 at 3:49 pm Nobin Says:

    Thank you for this grate solution.
    I want to work with Unicode Bengali number. I can calculate any English number with SUM() function on English with MySQL but Is there any way to calculate the Unicode Bengali number with SUM() function or anything with MySQL similarly PHP array_sum() function for calculating Unicode Bengali number or numeric value?

  17. On December 23rd, 2008 at 12:29 pm admin Says:

    @ Nobin

    Please check my new post:
    http://www.tanzilo.com/2008/12/23/php-mysql-unicode-number-add-subtract-etc-for-any-language/

  18. On December 28th, 2008 at 1:36 pm Alex Says:

    Thank you so much for sharing this. I am struggling few days to try to resolving this issue, and finally, you saved my life.

    Happy holiday!

  19. On December 29th, 2008 at 6:04 am PHP & MySQL: Creating a website in your local language smoothly - Learning Is Fun Says:

    [...] Step Four: You need to check my other posting for SELECT, INSERT & UPDATE your local language. Here goes my other article so that you can perform all required operations for storing and displaying information in browser smoothly: http://www.tanzilo.com/2008/10/13/php-mysql-unicode-solution-to-chinese-russian-or-any-language/ [...]

  20. On January 7th, 2009 at 2:20 pm Zach Shipley Says:

    You, sir, have saved my day. I’ve been struggling for quite a while for a simple way to work with unicode data in MySQL. All of my problems with invalid characters messing up my site have suddenly vanished after applying your concise steps. Thanks a million.

  21. On January 14th, 2009 at 4:11 am tootcsen Says:

    Hi, i’m looking for a php function that can convert chinese character to hexadecimal, do u mind to share your opinion / hints ? and this issue has struggled me for few months, getting urgent to get it done. hope you or someone here can help.

  22. On January 14th, 2009 at 5:55 am admin Says:

    @tootcsen

    hey,

    check my other two articles for hints

    1. http://www.tanzilo.com/2008/12/29/php-mysql-creating-a-website-in-your-local-language-smoothly/

    2. http://www.tanzilo.com/2008/12/23/php-mysql-unicode-number-add-subtract-etc-for-any-language/

    You should modify the code to adjust them in hexadecimal replace.

    i hope that will help

    thanks.

  23. On February 13th, 2009 at 8:05 pm bobby dee Says:

    Another cool tutorial, thanks again for sharing your experiences …

  24. On February 18th, 2009 at 3:32 am Roderick Kar Says:

    I ran into trouble with displaying Chinese using PHP/MySQL. I googled and found your article. Problem solved in 2 minutes. Thanks a lot!

  25. On February 26th, 2009 at 11:41 am Brecht Says:

    Hi,

    I am also working on several real estate websites and the current changes market forces my clients to offer the site in English, Spanish, Poolish and Russian. How do I handle this in the database and the PHP code? do I use UTF-8 for all of them?

    Thanks

  26. On February 26th, 2009 at 12:19 pm admin Says:

    @Brecht

    Hi there,

    if you follow this article as it is, you can show single or multiple language output in a page. Simply follow the article and test after you’ve done so!

  27. On March 8th, 2009 at 3:43 am phoenyo Says:

    Hi Bro,
    It works fine. Excellent post. Thanks
    pn

  28. On March 25th, 2009 at 1:50 am swathi Says:

    hi… this is swathi.i have some problem in my website.can u please help me…i have to develop my website wit telugu font using php…how can i do this simpy

  29. On March 25th, 2009 at 9:39 am admin Says:

    @ swathi

    if you are developing a simple site, Step One of this article should be enough for you.

    if you are developing a database based website in PHP, you need to follow all the steps.

  30. On April 18th, 2009 at 12:20 pm arifcsecu Says:

    Hello Bhia Assalmualikume
    It is nice to say that i have solved my prooblem relating to insert and retrieve bangla correctly using the idea from this pages

    thanks a lot to you

    Allah hafaz

    Arif
    Chittagong University
    Bangladesh

  31. On April 22nd, 2009 at 1:07 am S.G. Hussain Says:

    Hi,
    A good day to you.
    There is a little query regarding PHP, MYSQL and UNICODE in C panel. I’m new to it. My Musql is running well. I have a lot of Hindi and Urdu language Unicode characters in different databases. What I want is to store, retrive and display the characters as they are and not their hex equivalent codes since it creates problem in editing the text stored in mysql. It is easy to edit characters than their equivalent hex numbers. When I store the Hindi/Urdu text, for example, after
    converting them into hex, it is retrived and displayd nicely but now there is no
    character, only hex codes in Mysql and in the source page of browser. If I want to edit the data it is impossible if some change is needed. For that I need to keep Hindi/Urdu data at some other place then edit them and then convert them into hex first and then store them in Mysql. While I store data in mysql as original characters, the
    browser and the source page display only ???? ???? ??? like character. It does not
    recognize the stored data in Unicode characters. I want that the original characters
    should be sored in mysql (Storing is no broblem) retrived through echo in Php page and
    display in browser and source page of browser as they are and not their hex numbers.

    By the way where to place your class.unicode.php and what is this DATABASE INITIALIZATION.
    I attach the url of a page of mine here (http://www.nehi.in/hil/hil4.php). I work with C panel. I have set UTF-8 and utf8_Unicode_ci for all the fields, tables and databases through myphpadmin. I think I am not not converting the unicode successfully in htmlentities.

    I wonder if you have something to say.
    Thanks

  32. On April 22nd, 2009 at 1:17 am admin Says:

    @ S.G. Hussain

    Why don’t you develop a small application first in your localhost and try it?

    It would be better if you develop a small application and go to a complex one step by step.

  33. On May 1st, 2009 at 8:28 pm AustenD Says:

    Most helpful! Thank you very, very much!!!!!

  34. On May 3rd, 2009 at 12:40 pm Distorzija Says:

    Thanks a lot, mate!!! Thumbs up for this solution :)

  35. On June 1st, 2009 at 11:51 pm Berry Says:

    Hi.

    I’m making a website in english and Chinese using mysql databases

    I’m using one database and table for both languages

    like 1 tables with clubname_eng and clubname_chn

    I followed all the instructions, but somehow it doesn’t update the chinese text

    The first page has a from than contains both english and Chinese
    when pressing the send button, it runs updateclub.php
    but it only updates English text. Chinese text stays empty.

    the strange part is that when I print the chinese text on that update page it appears correctly. it’s just not updating

    than I tried utf8_encode command. but than I ended up with 2x more characters and that does not make any sense.
    but I got chinese text in my database and was able to read it. it’s just wrong text

    the last thing I tried is to add the text directly with phpmyaddmin.
    when I run the SQL it shows the text correctly, but on my page it give a square and a wrong Character for the word beijing (北京)

    What am i doing wrong

    And please help my solve this nightmare.

    Cheers

  36. On June 2nd, 2009 at 12:03 am admin Says:

    @ Berry

    Write two functions for two languages.
    Then use each function separately to handle each language.

  37. On June 2nd, 2009 at 1:34 am berry Says:

    what you mean with 2 functions?

    UTF-8 should be able to use all kind of charecters? or not?

    when I _Request the data from my form page, I can use in in the page. both languages at the same time. only the the text in the query is empty if it’s in Chinese

    Like the value $eng_city as the value beijing and the value $chn_city has the value 北京.

    when I echo this value they appear correct
    but when I use :

    mysql_query(“SET character_set_client=utf8″, $dbLink);
    mysql_query(“SET character_set_connection=utf8″, $dbLink);
    $sql_query = “UPDATE clubs SET city_eng = ‘$eng_city’ WHERE id = ‘$club_id’; “;
    mysql_query($sql_query, $dbLink) or die;

    mysql_query(“SET character_set_client=utf8″, $dbLink) or die;
    mysql_query(“SET character_set_connection=utf8″, $dbLink) or die;
    $sql_query = “UPDATE clubs SET city_chn = ‘$chn_city’ WHERE id = ‘$club_id’; “;
    mysql_query($sql_query, $dbLink) or die;

    it only updates the english text. the $chn_city value in the query is empty, but not if I echo it later on???

    also I added or die to the mysql_query to see if there is an error.
    but it doesn’t die

    Please help

    Cheers Berry

  38. On June 2nd, 2009 at 1:37 am admin Says:

    @ berry
    First try to insert the Chinese text.
    Follow all the steps described here carefully.
    When you succeed, then try to add English text.

  39. On June 2nd, 2009 at 1:39 am berry Says:

    one more this I want to ask.

    If I add the chinese text with phpmyaddmin, why I doesn’t show correct on my page?

  40. On June 2nd, 2009 at 1:41 am admin Says:

    @ berry
    I think you missed a step somewhere.
    Again try to follow all the steps described here one by one.
    Make sure you did not miss any one.

  41. On June 2nd, 2009 at 2:21 am berry Says:

    Thanks for the fast reply

    ok I made a new database with 1 table called Chinese
    in this table I made 2 fields.

    field 1: chn_name – Type = text – Collation = utf8_unicode_ci
    field 2: eng_name – rest same as field 1

    with operations I changed the database and table collation, too

    then I made 3 simple pages called
    http://www.1945mf-china.com/edit/test1.php
    http://www.1945mf-china.com/edit/test2.php
    http://www.1945mf-china.com/edit/test3.php

    test1.php has 2 textboxes, but I only programmed the first one so that it is Chinese only.

    here are the sources.

    test1.php

    Untitled Document

    test2.php

    Untitled Document

    test3.php

    Untitled Document

    I still have the same problem.

    If I type Beijing in Chinese, I won’t add the record.

    What am I doing wrong??????

    Cheers

  42. On June 2nd, 2009 at 2:23 am berry Says:

    I see that I can’t post the source code

  43. On June 2nd, 2009 at 2:46 am admin Says:

    @ berry
    Did you follow:
    Step One: SET THE CHARSET TO UTF-8 IN THE HEAD SECTION ??

  44. On June 2nd, 2009 at 2:48 am berry Says:

    yeah I did that,

    Dreamweaver does it for me, so I even can’t forget it.

  45. On June 2nd, 2009 at 2:52 am admin Says:

    @ berry
    I think you miss somewhere…
    Follow all the steps and try to develop a very small and very simple Chinese supporting code.

  46. On June 2nd, 2009 at 3:25 am Berry Says:

    These gave me a big headach ;-)

    But I solved the problem.

    I added

    $sql = “SET NAMES ‘utf8′”;
    mysql_query($sql, $dbLink);

    this step is not in your solution

    Now it writes and reads correctly

    thanks for all the help

    Cheers

  47. On June 2nd, 2009 at 3:30 am admin Says:

    @ berry
    No.
    You are wrong.
    That line is the last line of:
    Step Three: DATABASE INITIALIZATION

  48. On June 2nd, 2009 at 4:14 am berry Says:

    Sorry you’re right,

    I made a file connect.php that I include in all the php files that need to connect to that database

    this works for me, but as soon as I take the last 2 lines away, it doesn’t work anymore

    Very strange cause they both do the same thing but code differently

    Cheers

  49. On June 2nd, 2009 at 4:16 am berry Says:

    code one more time

    define(‘HOSTNAME’, ‘localhost’);
    define(‘USERNAME’, ‘*****’);
    define(‘PASSWORD’, ‘*****’);
    define(‘DATABASE’, ‘*****’);
    $dbLink = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
    mysql_query(“SET character_set_results=utf8″, $dbLink);
    mb_language(‘uni’);
    mb_internal_encoding(‘UTF-8′);
    mysql_select_db(DATABASE, $dbLink);
    mysql_query(“set names ‘utf8′”,$dbLink);
    $sql = “SET NAMES ‘utf8′”;
    mysql_query($sql, $dbLink);

  50. On June 2nd, 2009 at 4:20 am admin Says:

    @ berry
    But I am really really happy to know that your problem is solved at last.
    :)

  51. On June 23rd, 2009 at 3:59 am Ivan Says:

    Hello.
    Thank you for the post, it’s really helpful.
    I faced with a problem which is not exactly the same as you provided solution for, but may be you could help me.

    I read the post very careful, and made all changes (double checked).
    table, database, all fields collation set to utf8_unicode_ci.
    Proper meta tag is added as well.

    The problem:
    In phpmyadmin I see fields absolutely correctly:
    field1 field2
    室沙萨那(some chinese text here) Benefits: пока думаем… (Mix english and russian)

    The problem that after I made all chnages as you advised I got
    this output string for the fields:
    瀹ゆ矙钀ㄩ偅 (for field1)
    Benefits: 锌芯泻邪 写褍屑邪械屑… (for field2)

    Its chinese but not the same characters as in database. And as you can see russian text also replace by chinese characters.
    I double checked all preferences and so on but still cant understand what is wrong.

    Could you please advise me a direction..

  52. On July 1st, 2009 at 5:46 am Ivan Says:

    I created simple table, made everything according with your steps.
    After “UPDATE `probe` SET `NAME` = ‘你好’ WHERE `ID` = 1;” and SELECT after I get wrong output again and in PHP Admin shows the string correctly.

  53. On July 14th, 2009 at 8:12 pm Ivan Says:

    anyone could help me?

  54. On July 18th, 2009 at 12:18 am Ivan Says:

    can anyone help me?
    I tried apply SET names and SET CHARSET in different order and I studied MySql documentation from which the author created this article (with some additions which are not necessary), but funny thing that neither that guidance nor this article are correct. At least not always. I checked everything and tried exact stages step by step more than 10 times and still cant find way to fix it.
    But there is way – in PHP admin everything shows correct. But code of PHP Admin is quite difficult to understand and I couldnt find how they do it.
    I can provide access to DB if someone could help me…

  55. On July 21st, 2009 at 4:03 pm goodlife Says:

    Thanks a lot!! You helped me very well with Russian!!

    As it happened to Smokey on November 2nd, 2008 first I passed from ??????? before to мобРafter doing what is stated in this article. But it was because I had forgotten to take out the previous utf8_encode(….) I had on my code. After taking these ones out perfect!!

    God bless you & us!!

  56. On August 8th, 2009 at 1:07 am Fisi2000 Says:

    Thanks a lot! This saved my day :-)

  57. On October 7th, 2009 at 5:52 am WalkinRaven Says:

    Thank you, your blog looks very nice!

    I’m a newbie of PHP and found these words on manual:

    ———-
    A string is series of characters. Before PHP 6, a character is the same as a byte. That is, there are exactly 256 different characters possible. This also implies that PHP has no native support of Unicode. See utf8_encode() and utf8_decode() for some basic Unicode functionality.

    - PHP Manual: Language Reference -> Types -> Strings
    ———-

    I don’t understand that! So I searched it on google and found your article. But you have not even mention that.

    According to the manual, PHP strings are ‘exactly 256 characters’, that is to say you can’t create a string like ‘汉字’ in PHP. But I do did it in my code.

    It works! That puzzled me. Could I have some suggestions from you?

  58. On December 5th, 2009 at 10:54 pm sanjeew Says:

    I’m create website in the byethost.com and then import my wordpress blog in to it which is using unicode ” Sinhala Language in Sri Lanka” but all post of it display like “?????”. How to cahge DB type to unicode

  59. On December 5th, 2009 at 11:09 pm admin Says:

    @ sanjeew

    I think there is wordpress plugin for solution to this problem.

  60. On December 5th, 2009 at 11:26 pm sanjeew Says:

    how can i find this and its name please

  61. On December 5th, 2009 at 11:53 pm admin Says:

    @ sanjeew

    use google.com and find it yourself

  62. On December 20th, 2009 at 4:11 pm oliver Says:

    excellend, great … personally, I only needed to add

    mysql_query(“set names ‘utf8′”,$dbLink);

    and it worked a treat (already had the charset one)!

  63. On December 21st, 2009 at 8:57 am Ahsanullah Kakar Says:

    Dear Sir,
    You have done excellent job becuase you have worked exactly to counter the problem.
    I m also oracle database administrator and developer and now a days I have a website in pashto language.
    To conver this into php I am learning php as I have lot of knowledge about sql & database management so that is not problem for me.
    It will not be exegeration if I tell you I became your FAN. I want your personal email id to discuss lot of php and database issues with you.
    and in the last sir,
    How can we store wraped paragraphs like GHAZALS in sql and than retriew those records in php the same way we entered or if we have any way to wrap the paragraph in php programaticllay.

  64. On December 25th, 2009 at 5:28 am Kader Says:

    i want to use this code for my site with Turkish,English and Russian languages. But i can not work this code foru Turkish characters like “ıöü”

  65. On December 25th, 2009 at 6:21 am admin Says:

    @ Kader

    It should work for any language.

    I think you are missing one or more steps. Give a try and test!

  66. On December 30th, 2009 at 8:56 am mani Says:

    hello friends,

    i am created one website but i need to develop in tamil how to develop in step by step…

    by mani

  67. On January 1st, 2010 at 4:00 am Kader Says:

    Yes, you are right. I have some problem in my pages, i check step by step what i do. And correct the problem.

    Thank a lot for this article.

  68. On January 8th, 2010 at 2:57 am narinder Says:

    hello u r the genius in this conversion.
    i have one problem i making a dictionary to search words…the words are in punjabi language and its not ur working…

    after applying ur code..

    plz help

    Regards
    Narinder

  69. On January 8th, 2010 at 6:40 am Narinder Says:

    dear sir

    i want to make a search from database by words
    my code is:::
    mysql_query(“SET character_set_results=utf8″, $this->dbLink);
    $this->sqlQuery = “select * from view where Title like ‘%”.$searchterm.”%’ or Description like’%”.$searchterm.”%’”;
    $this->dbResult = mysql_query($this->sqlQuery, $this->dbLink);
    while($this->dbRow = mysql_fetch_object($this->dbResult))
    {
    echo ” . $this->convertToLocalHtml($this->dbRow->Title) . ”;
    echo ‘ ‘ . $this->convertToLocalHtml($this->dbRow->Description) . ”;
    }

    but the query not working.

  70. On January 8th, 2010 at 7:32 am admin Says:

    @ Narinder

    I think you should use “Step Six: SEARCHING DATA FROM THE DATABASE” for searching.

  71. On January 11th, 2010 at 1:32 am Fadzly Says:

    I can’t thank you enough. Your article made my life as a fellow developer so mush easier. May you find success and wealth as a result of your generosity with your knowledge.

  72. On January 11th, 2010 at 4:54 pm Sayed Karim Says:

    I want to insert my web form arabic input into mysql db by php Please please please help me how can i do this

  73. On January 11th, 2010 at 5:02 pm Sayed Karim Says:

    Please if you can show me the complete source code of html mysql db and php I will be very thank full to you Mr. Admin

  74. On January 11th, 2010 at 10:30 pm admin Says:

    @ Sayed Karim

    Did you follow all the steps and observed the result?

    If you follow the above steps, i think you can fix it.

  75. On January 22nd, 2010 at 4:52 am Rajeshkumar Says:

    Hai Sir,

    The above code is not working, i did according to your instructions but i dont know why….?

    in phpmyadmin i have selected for my database as well as table utf_unicode_ci.

    my code is:

    define(‘HOSTNAME’, ‘localhost’);
    define(‘USERNAME’, ‘root’);
    define(‘PASSWORD’, ”);
    define(‘DATABASE’, ‘bulb_china’);
    $dbLink = mysql_connect(HOSTNAME, USERNAME, PASSWORD);
    mysql_query(“SET character_set_results=utf8″, $dbLink);
    mb_language(‘uni’);
    mb_internal_encoding(‘UTF-8′);
    mysql_select_db(DATABASE, $dbLink);
    mysql_query(“set names ‘utf8′”,$dbLink);

    if(isset($_POST['add_country_cost']))
    {
    $country_name = $_POST['country_name'];
    $cost_kilowatt = $_POST['cost_kilowatt'];
    $currency = $_POST['currency'];
    mysql_query(“SET character_set_client=utf8″, $dbLink);
    mysql_query(“SET character_set_connection=utf8″, $dbLink);
    $sql_query = “insert into country_dollarcost (`id`, `country_name`, `currency`, `cost`) values (”, ‘$country_name’, ‘$currency’, ‘$cost_kilowatt’)”;
    mysql_query($sql_query, $dbLink);

    Can U give suggestions for this

    Thanks & Regards
    Rajeshkumar
    grajeshkumar.0186@gmail.com

  76. On January 23rd, 2010 at 12:36 am admin Says:

    @ Rajeshkumar

    I don’t see any problem in your PHP code.
    But other than PHP, there are other steps you must follow.
    Please follow each and every step one by one.
    That should solve the problem.

  77. On March 9th, 2010 at 12:59 am johnypham Says:

    I’m NEW to this stuff, but very happy with your code; it’s worked ok, except when do searching. I’m from Vietnam anyway. the search text only work with NO-ACCENT text; for example when I search for “Tháng Bảy (July)”, it return “Thang Bay” only.
    Could you point out what is the problem?
    Many thanks.

  78. On March 9th, 2010 at 1:42 am admin Says:

    @ johnypham

    I guess you are missing somewhere in the process or line(s) of code.

  79. On May 2nd, 2010 at 12:26 am sunil rana Says:

    Hello sir,
    I am doing trying to work on unicode is it possible for me to store in unicode_ci and show information into english or say slovak. Is it possible please guide on this.

  80. On May 2nd, 2010 at 10:00 am admin Says:

    @ sunil rana

    if you follow the above steps, you can store data in your desired language.

    But I am not sure about unicode_ci. You can give a try and see what comes up.

  81. On May 9th, 2010 at 1:11 am hrvač Says:

    Smokey, u saved my day with that bloody htmlentitys… thanks a bunch man ;)
    and tnx to the author ofcorse, but my preoblem from the start were entitys :D yippieeee

  82. On May 15th, 2010 at 3:54 am Pankaj Panjiyar Says:

    I’m new to PHP and tried to make website in Nepali language with database.
    Now I’m facing problem in adding , updating the records.
    mostly in case when we have some thing ” ‘ ” this symbol in between entries as this is one of the imp symbol used in Nepali fonts.

    Please help me out with this.

  83. On May 16th, 2010 at 4:09 am admin Says:

    @ Pankaj

    I think this is because your PHP version has configuration that restricts the use of single quote( ‘ )

    Some servers accepts direct us of ( ‘ ) and some others do not.

    Search google how to handle this.

  84. On June 8th, 2010 at 9:31 am hamza khan Says:

    enter english letter and match with chines charater and search for exect match
    %character%

    please guide me how i can do this
    and thants for this solution i had implemented succfully.

  85. On June 12th, 2010 at 1:40 am Anahit Says:

    I have some peoblems with russian, I try utf-8, utf8_unicode_ci and everything what is possible , but i can’t fix this problem, please can you help me? thank you!

  86. On June 12th, 2010 at 1:43 am admin Says:

    @ Anahit

    If you follow the steps one by one, Russian language supporting problem should be solved.

    Try all the steps carefully!

    And that’s it!

  87. On July 8th, 2010 at 6:04 am yogesh kumar Says:

    Sir,
    I followed your article.It is very nicely inserting the values in Mysql in local language.But when i tried to retrieve the values through an array,
    I got the output as “अब मेरा ” . canm you possibly brief me the reasons for the same .If you want I can send u the source code if you mention your email id .

    thanks

  88. On July 8th, 2010 at 10:31 am admin Says:

    @ yogesh

    Welcome…I think you are missing something…follow each and every step carefully.

  89. On August 18th, 2010 at 2:39 am Noor Says:

    Hello dear
    I did what you told me to each and evry step and it works on my localhost but when i upload the file to my server it again shows those ????????????? characters i checked my code more than 50 times it is as you said it should be but it works onl on m localhost not on my online host while i have made same setting to DB header and PHP queries
    please help me what else must i do
    thanks for your generous efforts ….

  90. On August 18th, 2010 at 6:37 am admin Says:

    @ Noor

    I think when you created the database, it was not created as utf8.

    May be your tables are utf8 but the database was not.

    (1) Database, (2) table and (3) targeted table fields all should be “utf8_unicode_ci” type.

  91. On August 26th, 2010 at 12:12 pm farman Says:

    Thanks thanks a lot ………..its done i m very much relax now you solve my very big prob….

  92. On August 29th, 2010 at 3:43 am Tony Says:

    You saved my days, my time, my energy and my life!!!!!

  93. On September 18th, 2010 at 10:15 am Andrei Says:

    Thank you so very much!!! It worked just fine…i’m a happy programmer now xD

  94. On September 23rd, 2010 at 2:07 am jitendra pradhan Says:

    hello sir,

    i used this code for my application to shows records in hindi in database fields and also at html pages and it works fine.

    But i faced one problem is that when i import my local database(contains hindi text) on server and run the application then it shows the text in unicode form like chinese symbol on html pages of server.

    please give me proper suggestions for that.

    thanks

    jitendra

  95. On November 4th, 2010 at 2:17 am linesh jose Says:

    Thanks dude :)

  96. On December 24th, 2010 at 10:46 pm Yogananth Says:

    Thanks thanks a lot.
    I’m searching everywhere but I get solution in here .

  97. On December 28th, 2010 at 1:34 am jayapala Says:

    Hi this is Jayapala ,i’m facing some problem
    PHP – MySQL: Unicode solution to English, Kannada or any language,
    But my facing some error – Adding the Dynamic data in php,
    so…please can you give me one example for Php/Mysql for Dynamic Page(Adding Text Values)

  98. On December 28th, 2010 at 1:39 am admin Says:

    @ jayapala

    please follow all the above steps and your problem should be solved. may be you have missed one or one more somewhere.

  99. On January 18th, 2011 at 6:15 am Technology News Says:

    Thanks a lot. You piece of code really helped me to complete my acadamic project.

  100. On February 8th, 2011 at 11:37 am Artak Says:

    Thanks, this article helps me save some time and some nervs.

    Best Regards.

  101. On March 19th, 2011 at 10:55 am gabrielem Says:

    Very usefull!! Thank You!

  102. On April 5th, 2011 at 8:30 am Andrews Mathew Says:

    hai sir,
    u r great. ur tutorial is nice and simple.
    can u make such a simple example in using ajax. im new to programming and using php and mysql. but ajax is a hard nut to crack
    tanx.

  103. On April 5th, 2011 at 8:34 am admin Says:

    @ Andrews

    thank you for your comment. ajax is simple. you can start learning ajax from here: http://www.w3schools.com/ajax/default.asp

  104. On April 18th, 2011 at 5:29 am vgergo Says:

    You are my hero!!! Thanks so much. We are creating a multi-language website and I’ve struggled so much with all these languagages and character encodings.

  105. On May 7th, 2011 at 12:10 pm adi Says:

    It works! Many thanks for your help and saving me many hours of headache.

    Inputing foreign characters works fine. However, the retrieving part of the foreign data displays only in ??? question marks. Strangely enough retrieving foreign characters displays correctly in my old non optimized older version. Any idea?

    Thanks again Adi

  106. On May 7th, 2011 at 12:40 pm admin Says:

    @ adi

    i am not sure. but I faced ?? when I missed “Step One: SET THE CHARSET TO UTF-8 IN THE HEAD SECTION”

    May be you are missing somewhere. You can try from first to last without avoiding any step.

  107. On May 18th, 2011 at 5:59 pm eko Says:

    hi sir,
    I was successful to inserting chinese character to database but
    I have a problem when I want to display chinese character.
    Please help me sir..

    this is my code:
    ————————————————————————————-
    mysql_query(“SET character_set_results=utf8″, $con);
    $sql_query = “SELECT * FROM user where email=’$user’ and password=’$pass’;”;
    $query = mysql_query($sql_query, $con);

    $result = mysql_fetch_array($query);
    $row = mysql_num_rows($query);

    if(($user == “”) && ($pass == “”))
    {
    print “e-mail and password empty !!!”;
    exit;
    }
    if($row != 0)
    {
    if($pass != $result['password'])
    {
    print “Password salah !”;
    }
    else
    {
    setcookie(“username”,$user);
    print “Welcome “.$result['First_Name'].” “.$result['Mid_Name'].” “.$result['Last_Name'].”
    Klik To HomePage“;
    }
    ——————————————————————————————-

  108. On May 18th, 2011 at 9:59 pm admin Says:

    @eko

    Well. I originally wrote this code for Chinese language. So, it surely works as I tested too.

    I think you are missing one or more steps out of all the steps.

  109. On July 16th, 2011 at 9:32 am Curtis Stanier Says:

    I just wanted to say thankyou. I have been having no end of trouble with PHP, SQL and Oriental Character Sets. This solved it, and for PDO’s too! Brilliant :)

  110. On July 20th, 2011 at 2:08 am shanka Says:

    thank you buddy….

  111. On July 31st, 2011 at 3:35 pm bDas Says:

    so many thanks…. may god bless you…

  112. On August 5th, 2011 at 11:00 pm syldie Says:

    Oh my God , I have to say 非常谢谢您。 I found this one for two days , bu I finaly got Good Answer . My I could buy a soda for you , thank you alot

  113. On August 10th, 2011 at 4:59 am Sourabh Chawla Says:

    you are toooo good dude…. but one thing is we have to first translate in google then copy paste in our editor… is this any thing that like google transalte editor….?

    pls reply on this…. waiting for ur reply…. :)

  114. On August 10th, 2011 at 6:42 am admin Says:

    @ Sourabh

    I do not know. please use Google to find the answer. :)

  115. On August 12th, 2011 at 2:08 am shishir kamal Says:

    Hi,
    i followed the steps provided by you and getting the data correctly in Phpmyadmin like (我的秋天) , but not able to see the same result while connecting from SqlYog , it comes like block .
    please advice how can i see the correct data .

    Also, when i had collation utf8_general_ci the characters were like 我的秋天 , is there any way to change the it so it will become the same when we use utf8_unicode_ci ??
    Please help .

  116. On August 12th, 2011 at 4:26 am admin Says:

    @ shishir,

    please forget whatever SqlYog shows. SqlYog might not be compatible with unicode.

    just make sure if you get the data properly in your output page.

  117. On August 22nd, 2011 at 11:24 pm Anil Shakya Says:

    Dear,

    i am not using two lines when database select.

    mb_language(‘uni’);
    mb_internal_encoding(‘UTF-8′);

    and every things use according your guidelines. Every things working fine but PDF(use TCPDF) in Hindi is not working . Other languages (PDF) are working fine. can you hepl me?

    Thanks
    Anil

  118. On September 9th, 2011 at 5:44 am Imam ud din Says:

    I didn’t test your code because i want to insert my data in urdu format in database. My question is that how can i make entries into database because i don’t know how the the text can be written in urdu language in a text field or a text area so that it could be inserted in database. Please help me. Thanks.

  119. On September 17th, 2011 at 8:04 pm Carmen Says:

    Thank you sooo much. I have gadgets in different languages to display my artwork. I tried many codes, including utf-8…but nothing really worked until I tried yours.
    Great tutorial! Very well explained too.

    Thank you again.
    Carmen

  120. On October 6th, 2011 at 12:31 pm Techroid Says:

    Thanks bro :) . This scripts are very helpful.

  121. On October 30th, 2011 at 5:00 pm nan Says:

    that is amazing. thank you for your help

  122. On October 31st, 2011 at 4:55 am hanumantharaju Says:

    need php code convert english to kannada

  123. On November 5th, 2011 at 7:55 pm unknown Says:

    you saved me i almost give up i searched for like 3 hours god dammmm

  124. On November 10th, 2011 at 10:10 am help Says:

    Hi,

    I have a database containing chinese characters and i would like to implement an improved search function where the chinese characters (in both the html form and in the database) would be converted to han yu pin yin first before being compared so i can get words with same han yu pin yin (without the accents)

    Any advice?

    Thanks

  125. On December 7th, 2011 at 4:00 am Bhupendra Says:

    Really wonderful article :D

  126. On January 17th, 2012 at 7:15 pm iyad abu haibeh Says:

    Thank you alot, You saved my time for this issue, I’m building a multi languages web site with MySQL database, your way working with me perfectly, I can now insert diffirent languages word in one feild without any mistakes, I should to thank you for your easy way for explaining.

  127. On January 18th, 2012 at 12:20 am simone Says:

    Wow! Work perfect!
    I still need some solution for some forenger text that i take from a php variables.

    But this work grate for the data in the database!

    Thank You!

  128. On January 26th, 2012 at 10:02 pm Todd Says:

    Great post. You saved me hours!
    You’re a great teacher.
    Thanks!

Email will not be published

Website example

Your Comment: