views:

36

answers:

1

Hi,

how can i get Arabic content when i run MSSQL_QUERY? it appears as ???? i tried to do this $res=mssql_query($q); $row=mssql_fetch_row($res) echo iconv("unicode","utf-8",$row[0]) but in this case it shows the value as Chinese letters as 潬穬 any suggestion is highly appreciated

A: 

Well, try sending this to database before you select the arabic text:

SET NAMES utf8;

For example, when using PDO:

try {           
    $dbh = new PDO(
    'mysql:host=127.0.0.1;dbname=dbname',
    'root',
    'root',
    array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")
);
} catch (Exception $e) {
    echo $e->getMessage();
}

Secondly, make sure that all your files (PHP files, HTML templates) are saved with UTF-8 encoding.

Thirdly, if all that fails, try playing with the iconv() function a bit more:

echo iconv("Latin1_General_CI_AS","utf-8",$row[0]);
echo iconv("Arabic_CI_AS","utf-8",$row[0]);

And so on.

Richard Knop
SET NAMES 'utf8' is mysql statement while the question is about Microsoft SQL server 2005.however, thank you for your attention and help.my pages are saves as UTF-8and echo iconv("Latin1_General_CI_AS","utf-8",$row[0]);echo iconv("Arabic_CI_AS","utf-8",$row[0]); both of them prints nothing :(
Alaa
Well, I haven't worked with MSSQL yet but isn't there some equivalent to SET NAMES?
Richard Knop
unfortunately i dont know any equivalent in SQL server.the problem is that the standard output encoding of sql server is unicode, but when i convert it to utf-8 it becomes Chinese!!!however, if i got a solution, i will post it here for sureThanks
Alaa