Skip to main content

Storing unicode texts in MySQL with phpMyAdmin

Today, I've received a personal mail/request from Sivanantham Hemamalini, working for IT leisure in Singapore. Since I was in company when received the mail, I couldn't answer immediately. If I understand the question right, it is about inputting Unicode texts especially Tamil in phpMyAdmin.

PhpMyAdmin's default characterset is iso-8859-1 and so if we enter anything in the form, browser will convert it into numerical html entities. Say for example, if we enter தமிழ் and submit the form, it will convert it to & #2980;& #2990;& #3007;& #2996;& #3021;. Because of this browser's behavior, it will be difficult to store the Unicode text as it is.

Solutions

Immediate solution I could think of is changing or forcing the browser's character encoding into utf-8. In Mozilla Firefox, it can be set via View -> Character Encoding -> Unicode (UTF-8)

Another elegant solution might be changing the phpMyAdmin configurations so that it sends and sets proper charset in Content-Type header as Content-Type: text/html; charset=utf-8
To do this, we have to edit the config.inc.php file found at phpMyAdmin's root directory:
$cfg['DefaultCharset'] = 'utf-8'; and
$cfg['AllowAnywhereRecoding'] = true;
These change of configurations should send proper headers. Anyhow, if the lang cookie is already set to some other charset, it won't reflect the changes. So, one may need to clear the cookies to see the changes.

Comments

Anonymous said…
I edit the config.inc.php file to this,
$cfg['DefaultCharset'] = 'utf-8'; and
$cfg['AllowAnywhereRecoding'] = true;
But i am getting error stating "Can not load iconv
or
recode extension needed for charset conversion,
configure php to allow using these extensions or
disable charset conversion in phpMyAdmin."
what is the solution for this.
I am using windows XP and php,v 2.8.2.1
thanks in advance
Hema
Hema, as the error message says it couldn't load the iconv extension, as it is not enabled. You can enable and disable PHP extensions via php.ini configuration file.

Use phpinfo() function to find the path of php.ini file.
To enable the iconv extension, just uncomment the line ;extension=php_iconv.dll (that is just remove the leading semicolon ";") in php.ini
You may need to restart Apache for the changes to reflect. Again use phpinfo() to see if the module is enabled or not. Now, you're done.

This procedure applies to any PHP extensions on Windows.
Anonymous said…
Do you have to use phpMyAdmin? I would write a simple PHP script to accept the input correclty and post to the db. The other solutions sound like more work.

Popular posts from this blog

Save American College, Madurai

This post was written in 2008 and outdated now. For update, please check Save American College, Madurai (Update 2011) Update (2011-01-16) : Save American College, Madurai (Update 2011) I'm highly privileged to have 3 degrees (B.Sc. (Spl. Physics), PGDCA and MCA) from The American College, Madurai, South India . Unlike other "commercial" colleges, American College has given room for poor students and uplifted them. And unlike other "elite" colleges who'd give seat only for "intellectuals", American College has produced geniuses. In the recent months, the saddening thing is that the college is under divide (Principal Vs. Bishop). Here is the email I sent to alumnae lately informing about the informations that I received about the developments: Update (2011-01-16) : Save American College, Madurai (Update 2011) All: I was thinking that the " Save American College " campaign was a FUD . But, when I tried to understand the problem through my

Magic: T.K.Vadivel Pillai is above Cyril Takayama

Recently, I have been watching Cyril Takayama 's magic show in AXN channel. That reminded me of T.K.Vadivel Pillai 's magic show in Jaya TV. I have searched Vadivel's name in Wikipedia's Indian magicians article and to my surprise, his name was not present. In my opinion, T.K.Vadivel Pillai's magic is superior than Cyril's--especially, in one show, he could tell the name of the person whom the girl was thinking. Not really sure, why T.K.Vadivel Pillai could not be as popular as Cyril. Sidenote: I'm yet to see David Blaine 's magic and I still have a gut feeling that Vadivel's would be better.

Open source PHP frameworks and problems

I was using CakePHP for sometime and proposed CakePlus , another UIMS toolkit on the top of CakePHP but also altering some problematic core of it. The thread should explain the outcome of the post. And, then I noted Akelos framework has most of the things built in. Issues with frameworks esp. CakePHP Scalability not a priority - Developers aren't aware that we can't throw more and more hardware Excessive use of regular expressions Evangelist isn't aware that the framework throws many queries unnecessarily More memory consumption - 100M would never be enough for a simple project Poor coding standards and practices - Prolong use of extract() often leads to more memory consumption Can't use the native approaches or baked codes. The override approach always lead to hard to debug codes Poor architected codes and no clear defined approaches. People belong to the cult drives the direction and often throws unprofiled codes. No native provision to share codes between M-V-C and