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

Converting PSD with PHP/ImageMagick

After seeing feature rich options in Imagick PECL extension at Mikko Koppanen 's (the author) website and also impressed with ImageMagick 's features, I have decided to use it for the PSD to XHTML conversion website that I'm architecting and managing. Since, the team wants programming help for converting PSD images, I have tried it (documentation is sparse on PSD handling) Converting PSD to PNG/JPEG/etc Note that, flattenImages() is needed for layered/multi-page PSD file. <?php $im = new Imagick('test.psd'); $im->flattenImages(); $im->setImageFormat('png'); $im->writeImage('test.png'); ?> Extracting PSD layers One by one <?php $im = new Imagick('test.psd'); $im->setImageFormat('png'); for ($i = 0, $num_layers = $im->getNumberImages(); $i $im->setImageIndex($i); $im->writeImage('layer' . $i . '.png'); } ?> Note that, there is a better version below In a single call with writeIm...

Don't remove the wisdom tooth

The inspiration for this post is a post by Peter Claridge You're nearing 25 years, you've got painful wisdom tooth growth, you're even getting high fever due the pain, your dentist is asking Rs.15,000/- plus for removal/extraction and showing scientific papers claiming that wisdom tooth is unnecessary growth... First of all don't pluck it--unless you hit very very very serious problem. I was also about fell prey for one dentist whom tried to convince me a lot for the extraction surgery. With some sort of hesitation, I had to inform it to my Mom that time. She immediately suggested me to rinse with salt water and take mild foods for about 1-week. She strongly insisted that the pain will definitely go in 1-week time. To my surprise, that did really work for me. So, far I have suggested that to many people and all of them were about to have the surgery scheduled. Are you still going to pluck the wisdom tooth or just treating it with salt water rinsing?

NETELLER - Privacy and security design flaw

Yesterday, colleague of mine brought to my notice about a payment system called NETELLER and it's merchant API named NETELLER Direct API V4 . This NETELLER Direct API V4, helps the merchant to collect amount from users. It's simple--same just like early Authorize.net , along with the required amount you collect the user's id and password and post them to their API URL and they'll send you back with success or error codes in XML format. The major problem with these types of system is security and privacy --you lose both as you're forced to type your username and password in alien web page. If I remember right, this is was the case with Authorize.net and they changed their design to something like PayPal . The PayPal design is somewhat better as you never type or forced to type your username and password in other alien web pages. The alien merchant web page uses NETELLER Direct API V4 is forced to get user's NETELLER account and password. I'm much s...