Issue in storing arabic characters..help please

hello friend i have problem where the arabic fonts are not displaying in a proper manner in the database so please provide a solution for this…

1)we used utf8 for the database.
2)we tried utf_unicode_ci.
3)we tried utf_general_ci.

and i tried mysql_query(set names utf8);
before the execution then too its not getting solved.
in databse its showing ???
or some unwanted characters…

After some looking, I found: http://forums.mysql.com/read.php?103,142876,210144#msg-210144
Try what was suggested there. I don’t know Arabic, but have you tried to get data out – like onto a webpage, how does it display?

What server-side langauge are you using? If it’s php try adding this to the line imediatly after the database connection to MySQL is established:

mysql_set_charset('utf8',$link_id);  

There are six things you need to do to ensure that Unicode is your default. Arabic can be stored and displayed if these are present:

  1. Each table must be set as utf8:
    CREATE TABLE name {

    } DEFAULT CHARACTER SET utf8;

  2. DB connection php code:

<?php
$link = mysqli_connect('localhost', 'root', 'your password');
...
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Cannot set utf8 encoding.';
include 'your output.php'
exit();
}
?>

This will connect you to the db with utf8, if not it will tell you so.

echo out your values like this:

<?php echo htmlspecialcharacters($table_name['value'], ENT_QUOTES, 'UTF-8'); ?>

set your webpages as charset utf8 and save your code in utf8 encoding.

5)Keep in mind that your command prompt window likely will not properly display the Arabic. It is better to echo the text onto a webpage which will display it properly.

  1. Finally, you should also make sure the browser you are using is properly configured to read utf8.

That should cover it :slight_smile:

hello friends for the replys for my issue but i applied ur command in the program then too i am not getting it solved

i used a simple small program to solve this issue but its stores in the database??? in this manner so i am pasting it below just friend go through it and make it correct and give me a reply as fas as u can

<?php
if(isset($_POST[‘submit’]))
{
$conn = mysql_connect(‘localhost’,‘root’,‘local’);
mysql_select_db(‘test’);
//mysqli_set_charset(‘utf8’,$conn);
//mysql_set_charset(‘utf8’,$conn);
mysql_query(“SET NAMES ‘utf8’”);
mysql_query(“SET CHARACTER SET ‘utf8’ COLLATE ‘utf8_unicode_ci’”);

				/*if (!mysqli_set_charset($conn, 'utf8'))

				{
						echo htmlspecialcharacters($table_name['username2'], ENT_QUOTES, 'UTF-8');
						exit();
				}*/

$sql=“insert into testing(testfeild) values('”.$_POST[‘hello’].“')”;
//mysqli_query($conn,$sql);
mysql_query($sql);
echo $_POST[‘hello’];

}
?>
<html>
<meta http-equiv=“Content-Type” content=“text/html; charset=utf-8” />
<body>
<form name=“fname” method=“post”>
hello:<input type=“text” name=“hello” />
<input type=“submit” name=“submit” value=“submit” />
</body>
</html>

use proper code wrapping

Change the line:

//mysql_set_charset('utf8',$conn);

to

mysql_set_charset('utf8',$conn);

friend still in the database its showing in the manner of ??? this just u run in ur system this and give me a solved solution friend …

First thing: How does it displays in the browser?
And the other: Did you tried with following code after database connection?:

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'"); 

Lastly: How are you inserting the contents in DB: through form fields or manual insert in db?

hello friend i am inserting to the feilds through the form the program which i am used id above which u can see… and tell me the correction i need only one thing inside the database i should see it as in arabic when i enter it in arabic
i tried it so many times friend just give me path way to lighten it up

How does it display on your webpage? It will not display properly in your database window, so don’t worry about it.

Also your notes use mysqli but your code uses mysql. I would recommend upgrading to mysqli (mysql improved).

You need to close with a </form> after you specify the input type.

I recommend reading Kevin Yank’s ‘Build Your Own Database’, especially chapters 2 - 4.