how to insert arabic text in mysql

Step-1 Create database table

CREATE TABLE <code>language_messages</code> (
  <code>lang_id</code> int(11) NOT NULL auto_increment,
  <code>en</code> varchar(500) NOT NULL,
  <code>ar</code> varchar(500) NOT NULL,
  PRIMARY KEY  (<code>lang_id</code>)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

INSERT INTO <code>language_messages</code> VALUES (1, 'About Us', 'من نحن');
INSERT INTO <code>language_messages</code> VALUES (2, 'Contact Us', ' تواصل معنا ');
INSERT INTO <code>language_messages</code> VALUES (5, '', 'శ్రీనివాస్ తామాడా');

Step-2 create connection

$conn=mysql_connect(HOST,DB_USER,DB_PASS) or die(mysql_error());
$db=mysql_select_db(DB_NAME,$conn) or die(mysql_error());
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");

Step-3 View output in HTML page

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--<html dir="rtl" lang="ar" xml:lang="ar" xmlns="http://www.w3.org/1999/xhtml">-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<?php $sql = "select * from language_messages"; $res = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($res)) { echo" ". $row['en']; echo" ". $row['ar']; } ?>
</body>
</html>
(Visited 162 times, 1 visits today)

Leave a Comment.