1

I've got a database contains some arabic data, It works when I select all data. But when I use WHERE statment, something = something, something like something. It doesn't work. I've escaped the strings and I've tried to use N

$full = "SELECT * FROM $table WHERE question='$question'";

And I've printed the syntax

SELECT * FROM arabic WHERE question='متي اصدرت هيئه الامم المتحده الاعلان العالمي لحقوق الانسان ؟'

But it doesn't work

Solved:

I've done these steps: http://tympanus.net/codrops/2009/08/31/solving-php-mysql-utf-8-issues/

That1Guy
  • 7,075
  • 4
  • 47
  • 59

2 Answers2

0

I think it's an encoding problem..

Make sure that your connection is set to utf8 right after you make the connection and before your query by this line:

mysqli_set_charset($con,"utf8");
Firas Rassas
  • 509
  • 4
  • 12
  • `mysqli_query($conn, "SET character_set_results=utf8"); mb_http_output('UTF-8'); mb_internal_encoding('UTF-8'); mb_http_output('UTF-8'); mb_http_input('UTF-8'); mb_language('uni'); mb_regex_encoding('UTF-8'); ob_start('mb_output_handler'); mb_language('uni'); mb_internal_encoding('UTF-8'); mysqli_query($conn, "set names 'utf8'"); mysqli_set_charset($conn, "utf8"); ` Nothing more to do – Ahmed Nezar Oct 17 '15 at 12:02
  • The problem is your query content is really not equal to content in database because of encoding. Is your file encoding utf8? and your sql table too? – Firas Rassas Oct 17 '15 at 12:07
  • I think if it is not it wouldn't print all data without where – Ahmed Nezar Oct 17 '15 at 12:10
  • try to run this query: SELECT * FROM arabic WHERE question like '%ا%' – Firas Rassas Oct 17 '15 at 12:12
  • Worked, So what I should do to make it work with inserted data? – Ahmed Nezar Oct 17 '15 at 12:21
  • Ok that means that your problem is not because it's arabic.. it's just your query didn't find any rows that match your statement.. What you've tried here is searching questions that have "ا" letter in them.. – Firas Rassas Oct 17 '15 at 12:22
  • But, The value which I inputed is copied from the database I haven't even wrote it – Ahmed Nezar Oct 17 '15 at 12:23
  • ok it happened to me once.. try to write it and not copy it. and try to add % before and after.. SELECT * FROM arabic WHERE question='%متي اصدرت هيئه الامم المتحده الاعلان العالمي لحقوق الانسان ؟%' – Firas Rassas Oct 17 '15 at 12:25
  • Ok, Now I've tried to search for "م" it printed only to values, And there are more in the database. Also it printed it for me like this س1 ماذ and س9 بم ر& and these aren't arabic by anyway I've tried to put `header('Content-Type: text/html; charset=utf-8');` and `echo "";` also nothing and when I tried to search for متي it didn't print anthing and I've tried this `SELECT * FROM arabic WHERE question='%متي اصدرت هيئه الامم المتحده الاعلان العالمي لحقوق الانسان ؟%'` it printed nothing. – Ahmed Nezar Oct 17 '15 at 12:31
  • Where did print it like this? in browser or on log? – Firas Rassas Oct 17 '15 at 12:39
  • i still think there is something with arabic question because it works perfectly with english data with the same code – Ahmed Nezar Oct 17 '15 at 13:07
  • It happened to me once, and the problem was spaces between words.. they looked like space but it was different character so the query didn't match them. I Think that is your problem.. try to edit the text in database and write it again(not copy) then write in query and do it. – Firas Rassas Oct 17 '15 at 13:13
  • Do you mean to write them without spaces? – Ahmed Nezar Oct 17 '15 at 13:16
  • No, but maybe that a good direction to start check with.. In the previous comment I meant to write the text(in DB) again so if there were any characters that looks like space but it's not, you will replace them with real spaces. – Firas Rassas Oct 17 '15 at 13:18
  • I've tried it with one value to check and it didn't work – Ahmed Nezar Oct 17 '15 at 13:26
  • Then I'm sorry.. I recommend to build a little new script with new db and try there.. and be careful with every line you add in your script. I'm sure it's a little thing that make this problem. – Firas Rassas Oct 17 '15 at 13:29
0

Create database/table with 'utf8_general_ci' Collection.

Database Records:

id |    name    
1  |    الترجمة
2  |    دينار

PHP script:

$conn=mysqli_connect('localhost','root','');
mysqli_select_db($conn,'test_data');
mysqli_query($conn,"set names utf8");

$sql="select * from employee where name='الترجمة'";
$fire=mysqli_query($conn,$sql);
while($row=mysqli_fetch_assoc($fire)){
    print_r($row);
}