Tuesday, 12 February 2013

Store any language data in your Mysql Database with unicode solution

Do you want to use any language data in your data base like Hindi(हिंदी), Chinese(中国的), Arabic(العربية), Russian(русский) etc...

Follow some Steps:-

Step First: 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. 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
......
</body>
</html>

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.

Step Three: DATABASE INITIALIZATION

When you initialize the database connection, please add the “extra lines” in your database file.
 
define('HOSTNAME', 'localhost');
define('USERNAME', 'user_name');
define('PASSWORD', 'password');
define('DATABASE', 'database_name');

$dbcon= mysql_connect(HOSTNAME, USERNAME, PASSWORD); 

mysql_query("SET character_set_results=utf8", $dbcon);
 
mb_language('uni');
 
mb_internal_encoding('UTF-8');

mysql_select_db(DATABASE, $dbcon);
mysql_query("set names 'utf8'",$dbcon); 

mysql_query("SET character_set_client=utf8", $dbcon);
 
mysql_query("SET character_set_connection=utf8", $
dbcon); 

mysql_query("SET character_set_results=utf8", $dbcon);


Now you can easily select,insert and Update any Language data...









No comments:

Post a Comment