Thursday, 10 July 2014

How to manage international languages in MySQL database


If you are making a web site where multiple languages used like Arabic, French, Hindi or Urdu then your MySQL database default settings is not valid to do that to insert all languages in database. If you insert data in your database and database is not configured as I am going to show you in this tutorial then your data will be look like ????? and you lost your data.

So now i am going to tell you how to configure database to accept international languages.

Very important HTML settings you have to add a meta for character set UTF-8

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

Now create table in your database its default character set will be <strong>latin1_swedish_ci</strong>

You have to change it to <strong>utf8_general_ci</strong>

Here is the insert query

mysql_query("INSERT INTO `comments`(id,comment) values (N'$id',N'$comment')");

N’$id’ N is stands for national regional language character set.

Fetch code and query

<?php
include('db.php');
mysql_query("set character_set_results='utf8'");
---- code ---
?>

Now your database is configured to insert all international languages.

No comments:

Post a Comment