PHP get Arabic Content from SQL SERVER
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 i开发者_运维问答t shows the value as Chinese letters as 潬穬
any suggestion is highly appreciated
Just use Unicode data types. The Unicode data types are nchar, nvarchar, nvarchar(max), and ntext and you must precede all Unicode strings with a capital letter N.
INSERT INTO TableName (ColumnName) values(N'Arabic Text')
Firstly try installing the sqlsrv drivers found on http://msdn.microsoft.com/en-us/library/cc793139%28v=sql.90%29.aspx. After following the instructions correctly, when connecting to sql server use :
$connArr = array(
"Database" => $dPconfig['dbname'],
"UID" => $dPconfig['dbuser'],
"PWD" => $dPconfig['dbpass'],
"CharacterSet" => "UTF-8"
);
$conn = sqlsrv_connect($dPconfig['dbhost'], $connArr) or die("cannot connect");
it should work just fine Also see help docs of sqsrv drivers for other encodings. Hope it helps.
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.
精彩评论