php - Weird MySQL encoding issue -


i have column in pages table arabic data.

if this...

@mysql_query( "select title pages web_id = '$id'" ); 

i correct data, in arabic.

but if call same function again, in fact, it's in loop, second time brings me garbage data. looking this

"تنظيم الأوقا٠العامة اقرأ قطاع 

also, if before query, either of this:

@mysql_query("set names 'utf8'"); @mysql_set_charset( 'utf8' ); mysql_query("set character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'" ); 

i garbage data, on first call. what's happening here?

note database, table , field collations set utf8_bin

some random hints:

try not use @ operator. suppress error message.

you need escape input parameters properly:

mysql_query("select title pages web_id = '" . mysql_real_escape_string($id) . "'"); 

you need check return value of mysql_query():

$res = mysql_query("select title pages web_id = '" . mysql_real_escape_string($id) . "'"); if(!$res){     die('could not fetch page title'); // see mysql_error() error message } 

make sure php source code saved utf-8. decent editor allow save utf-8 , display current encoding in status bar.

check table definition. mysql allows set per table , column encodings.

set connetion encoding mysql_set_charset().

make sure browser renders page utf-8. in php, can generate appropriate http header with:

header('content-type: text/html; charset=utf-8'); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -