Page 1 of 1

MS SQL + PHP issue displaying UTF-8 characters

Posted: Sun Apr 26, 2009 6:57 am
by josephchoufani
Hi,

I am having a problem displaying arabic characters from Microsoft SQL Server database.

I am using the following:
Apache 2.2.8 for windows + PHP 5.2.6 for windows + Microsoft SQL Server 2005 Express + Microsoft SQL Server 2005 Driver for PHP

The characters are being displayed as ???? in the web application. I tried to change the encoding with no success.

what I'm looking for is something similar to MySQL's: SET NAMES 'utf8'

Sample Code:

Code: Select all

<?php header("Content-type: text/html; charset=UTF-8"); ?>
<pre><?php
$serverName = '[Server]';
$connectionInfo = array( "Database"=>"[Database]");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn )
{
   echo "Connection established.\n";
   $rslt = sqlsrv_query($conn, 'SELECT * FROM [Table]');
   while($r = sqlsrv_fetch_array($rslt,SQLSRV_FETCH_ASSOC)) print_r($r);
}
else
{
   echo "Connection could not be established.\n";
   die( print_r( sqlsrv_errors(), true));
}
sqlsrv_close( $conn);
echo "Connection closed!";
?></pre>
Sample Output:

Code: Select all

Connection established.
Array
(
    [ID] => 10
   

Code: Select all

=> 01
    [AName] => ????
)
Array
(
    [ID] => 11
   

Code: Select all

=> ? 
    [AName] => ????
)
Array
(
    [ID] => 12
   

Code: Select all

=> ? 
    [AName] => ?????? 
)
Array
(
    [ID] => 13
   

Code: Select all

=> ? 
    [AName] => ????? ????? ? ????? ????? ? ???? ??????? 
)
Array
(
    [ID] => 14
   

Code: Select all

=> ? 
    [AName] => ?????? ???????
)
Array
(
    [ID] => 15
   

Code: Select all

=> ? 
    [AName] => ?????? ????????
)
Array
(
    [ID] => 16
   

Code: Select all

=> ? 
    [AName] => ???? ???????
)
Array
(
    [ID] => 17
   

Code: Select all

=> ? 
    [AName] => ?????? 
)
Array
(
    [ID] => 18
   

Code: Select all

=> ??
    [AName] => ?????? ?????
)
Array
(
    [ID] => 21
   

Code: Select all

=> 00
    [AName] => ?????? ??? ???? ???? ????
)
Array
(
    [ID] => 22
   

Code: Select all

=> ??
    [AName] => ????
)
Connection closed!
Thanks

Re: MS SQL + PHP issue displaying UTF-8 characters

Posted: Mon Apr 27, 2009 5:53 am
by josephchoufani
I figured it out, I used the ADODB COM:

Code: Select all

$conn = new COM("ADODB.Connection", NULL, CP_UTF8);
Reference: http://bugs.php.net/bug.php?id=18169

Cheers