Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can not search arabic in mysql Quran Database with php

I am newbie in web programming so I do apologize if I say something wrong. I am writing a simple php script to search in an Arabic mysql DB (Quran database from this website http://qurandatabase.org/Database.aspx - mysql query file format - Arabic(Original)) but I have a very simple problem, which is what I receive by GET method in my php script is not what I entered to search and something add some unwanted Arabic character to my searched string. my codes and out puts are as follows: my html code is:

 <!DOCTYPE html>
 <html xmlns="http://www.w3.org/1999/xhtml" lang="ar" xml:lang="ar">
     <meta http-equiv="content-type" content="text/html; charset=UTF-8">
     <body>
         <form action="p.php" method="get" accept-charset="UTF-8">
             Word Search: <input type="text" name="word"/>
             <input type="submit"/>
         </form>
     </body>
 </html>

my php code is:

<?php
 header('Content-type: text/html; charset=utf-8');
 $DBServer="localhost";
 $DBUser="root";
 $DBPass="1";
 $DB="Quran";
 $DBTable="Quran";
 //echo "Welcome".$_GET["fname"];
 $Word=$_GET['word'];
 echo $Word;
 echo "<br />";
 echo "<br />";
 $con=mysql_connect($DBServer,$DBUser,$DBPass);
 if(!$con)
 {
     die("DB Connection error: ".mysql_error());
 }
 mysql_select_db($DB,$con);
 echo "<br />\n";

 echo "<br />\n";
 echo "<br />\n";
 echo "<br />\n";
 echo "select * from $DBTable where AyahText like '%".$Word."%'";
 echo "<br />\n";
 $select="select * from $DBTable where AyahText like '%ﻢِﻧَ ﺎﻠْﺠِﻧَّﺓِ ﻭَﺎﻠﻧَّﺎﺳِ%'";
 echo $select;
 echo "<br />\n";
 echo "<br />\n";
 $select="select * from $DBTable where AyahText like '%".urldecode($Word)."%'";
 echo $select;
 echo "<br />";
 $result=mysql_query($select);
 //$result=mysql_query("select * from $DBTable where VerseID=$Word");
 $LastSura=1;
 echo $LastSura;
 echo "<br />";
 while($row=mysql_fetch_array($result))
 {
     echo "salam";
     echo $row['SuraID']."\t".$row['VerseID']."\t".$row['AyahText'];
     echo "<br />";
     if($row['SuraID']!=$LastSura)
     {
         echo "<br />";
         echo "<br />";
     }
     $LastSura=$row['SuraID'];

 }
 mysql_close($con);
 ?>

and I enter this string in my html text box:

مِنَ الْجِنَّةِ وَالنَّاسِ

but I get this string with few difference in output which you have to test it yourself:

مِنَ الْجِنَّةِ وَالنَّاسِ

select * from Quran where AyahText like '%مِنَ الْجِنَّةِ وَالنَّاسِ%'

select * from Quran where AyahText like '%مِنَ الْجِنَّةِ وَالنَّاسِ%'

select * from Quran where AyahText like '%مِنَ الْجِنَّةِ وَالنَّاسِ%' 1

and it cause my search to fail .

I don't know if this copy and paste for questioning keeps my correct output to show you correctly or not but in my browser in الْجِنَّةِ and النَّاسِ up on ن I have unwanted ِ or َ in my output. so much thanks for any help.

like image 633
golden_boy615 Avatar asked Dec 04 '12 14:12

golden_boy615


1 Answers

The difference between مِنَ الْجِنَّةِ وَالنَّاسِ and مِنَ الْجِنَّةِ وَالنَّاسِ is that a non-printable character is in a different place. Depending on the collation you are using this makes the strings equal or different in MySQL, affecting the query results:

mysql> select 'مِنَ الْجِنَّةِ وَالنَّاسِ' = 'مِنَ الْجِنَّةِ وَالنَّاسِ' collate utf8_general_ci general;
+---------+
| general |
+---------+
|       0 |
+---------+
1 row in set (0.00 sec)

mysql> select 'مِنَ الْجِنَّةِ وَالنَّاسِ' = 'مِنَ الْجِنَّةِ وَالنَّاسِ' collate utf8_unicode_ci unicode;
+---------+
| unicode |
+---------+
|       1 |
+---------+
1 row in set (0.00 sec)

Change the collation defined for the column to get the results that you want, for example:

alter MyTable modify MyColumn text collate utf8_general_ci;
like image 196
Joni Avatar answered Sep 30 '22 02:09

Joni