Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

How to match junk characters in mysql database with arabic letters with PHP and MYSQL

My question in brief here:

The site is developed with PHP as front end and mysql as backend.

I am registering in my site by entering the arabic letters. And the value also inserted in mysql database. But it is not in the format what i entered. It looks like junk words.

Now my problem is when i try to login i can't able to match the input what i entered. I am stuck with this place.

Any ideas or suggestion will be helpful and grateful.

thanks in advance..

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This problem should be solved in an earlier stage. Arabic character do not fit in a non-unicode databasetable. That's the real problem.

You should use Unicode tables as well as a Unicode connection to your MySQL database.

Set the default character set of your table to utf8 and make sure the connection to your database is also using this character set:

$conn = mysql_connect($server, $username, $password);
mysql_set_charset("UTF8", $conn);

See also: http://nl3.php.net/manual/en/function.mysql-set-charset.php

Check the character set of your current connection with:

echo mysql_client_encoding($conn);

See also: http://nl3.php.net/manual/en/function.mysql-client-encoding.php

When creating your tables do something like this:

create table user (
    // Your table definition
) default charset = UTF8

If you have done these things and add a user which contains arabic character to your table, you will see it is displayed correct. Now the comparison will be easy.

Good luck!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...