Reputation: 1020
I have looked all over the net trying to find a single tutorial about inserting arabic letters into mysql via HTML & PHP
my HTML page looks like this
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
and my php page is like this
// Connects to your Database
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("castt") or die(mysql_error());
mysql_query("SET NAMES 'cp1256'");
mysql_query('SET CHARACTER SET cp1256');
when I browse the mysql DB, it appears like "?????"
any suggestion?
Upvotes: 3
Views: 10354
Reputation: 1020
I have solved by adding
mysql_query("set character_set_server='utf8'");
mysql_query("set names 'utf8'");
right after the connection
Upvotes: 4
Reputation: 31
Great it is working....... :) let me show you code.
Step-1 Create database table
CREATE TABLE `language_messages` (
`lang_id` int(11) NOT NULL auto_increment,
`en` varchar(500) NOT NULL,
`ar` varchar(500) NOT NULL,
PRIMARY KEY (`lang_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;
INSERT INTO `language_messages` VALUES (1, 'About Us', 'من نحن');
INSERT INTO `language_messages` VALUES (2, 'Contact Us', ' تواصل معنا ');
INSERT INTO `language_messages` 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"<br />". $row['en'];
echo"<br />". $row['ar'];
}
?>
</body>
</html>
Upvotes: 3
Reputation: 449385
You are making your database use cp1256
while you declare your output as UTF-8. That can't work.
Replacing cp1256
by UTF8
might already help.
Upvotes: 6