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

Humble Award - Dr. A.N. Sreevatsan

Dr. A.N. Sreevatsan , ENT specialist located in Adyar, Chennai is one of the gems available in medicines. No assistants in his consulting room and he'd take at least 15mins for every patients. So far I have referred many and all are happy with his approach. Every wannabe doctor should visit him personally to understand his approach. I wish him to be more famous than now. Update (2010-11-21) : Added link to Google Map Keywords : Sreevatsan, Srivatsan, ENT, Adyar, Chennai, Hospital, Doctor

Top Indian web startups

Disclaimer: This list contains some of our team's projects Sites that are useful and usable erail.in - created by a single person and serves useful to quickly find availability in Indian trains ClearTrip - seems to be inspired by many other sites like Vayama , but able to get better UI RediffMail - speed is the big boost Myntra - good idea, but poor UI redBus - good idea, but poor UI and execution Sites from The Times Group are also of good idea, but poorly executed/architected. They clearly try and target the web startup "gap" Sites that are innovative (world's first/never seen before kind) SocialAV - World's first and only antivirus building community (by our team) CSSilize - World's first and only project management tool for slicing works (by our team) jobreapr - World's first and only fixed price job search engine (by our team)

How to interview a candidate?

How to interview a candidate/programmer -- Version 0.0.1 Note : It's based on my process of short-listing candidates/programmers and experiences so far in selecting and building my great team. I'll expand it whenever I get time and will amend versions. Not many of you were wise in the way the world judges wisdom. Not many of you had great influence. Not many of you came from important families. But God chose the foolish things of the world to shame the wise, and he chose the weak things of the world to shame the strong. - St. Paul Core facts Interviewing is a serious effort and interviewing has great career prospects. Take it as a serious profession. Interviewer/interviewee – no one is genius. You cannot find a person who knows everything. You're not a foreteller and so you cannot identify people by appearance. That's the need for the interview. No interview question is right or wrong. You need to take good decision based on many factors—not just...