ID:               18169
 Comment by:       alex dot bazan at concatel dot com
 Reported By:      joesterg at hotmail dot com
 Status:           No Feedback
 Bug Type:         MSSQL related
 Operating System: Windows 2000 Server
 PHP Version:      4.1.2
 New Comment:

Pinging this bug. Opened in 2002 and still without an answer. I'm
having trouble too with non-latin characters with Sql Server.


Previous Comments:
------------------------------------------------------------------------

[2007-11-11 01:46:24] etraxis at gmail dot com

Looks like nobody is going to fix the issue. ;(
I haven't solution but I have workaround that I use in my project and
it works - it's sending and receiving data as binary.

=========
 Example
=========

Let's assume, we have following data table, that allows us to store
unicode values (using UCS-2 encoding):

    create table mytable
    (
        myfield nvarchar (100) null
    );

Below is the code to work with:

    $link = mssql_connect('dbhost', 'username', 'password');
    mssql_select_db('database', $link);

    // sending data to database
    $utf8 = 'some unicode UTF-8 data';  // some Greek text for example
;)
    $ucs2 = iconv('UTF-8', 'UCS-2LE', $utf8);

    // converting UCS-2 string into "binary" hexadecimal form
    $arr = unpack('H*hex', $ucs2);
    $hex = "0x{$arr['hex']}";

    // IMPORTANT!
    // please note that value must be passed without apostrophes
    // it should be "... values(0x0123456789ABCEF) ...", not "...
values('0x0123456789ABCEF') ..."
    mssql_query("insert into mytable (myfield) values ({$hex})",
$link);

    // retrieving data from database
    // IMPORTANT!
    // please note that "varbinary" expects number of bytes
    // in this example it must be 200 (bytes), while size of field is
100 (UCS-2 chars)
    $result = mssql_query("select convert(varbinary(200), myfield) from
mytable", $link);

    while (($row = mssql_fetch_array($result, MSSQL_BOTH)))
    {
        // we get data in UCS-2
        // I use UTF-8 in my project, so I encode it back
        echo(iconv('UCS-2LE', 'UTF-8', $row['myfield']));
    }

    mssql_free_result($result);
    mssql_close($link);

------------------------------------------------------------------------

[2007-06-14 08:37:39] giannisptr at yahoo dot gr

Has anyone found a solution to the encoding problem?????
I am using a web service to get a string of data from an sql server
2000 database. When i invoke the web service from php, greek characters
are replaced by character '?'.

------------------------------------------------------------------------

[2006-09-21 06:59:28] gautam dot webprogram at yahoo dot com

I want to connect php with MS SQL Server 2000 I have used the folloing
code in PHP:

<? 
    $connection = mysql_connect ("localhost","user name","password"); 
        
        if (!$connection) { 
        echo "Couldn't make a connection!"; 
        exit; 
    } 
        ?>



The code doesn't execute.

------------------------------------------------------------------------

[2006-09-09 01:18:11] aireater at gmail dot com

I still have the same issue with the latest Windows binary 5.1.6 and MS
SQL Server 2005 Express, Standard, Enterprise on Windows XP, 2003
Server. It never works.

------------------------------------------------------------------------

[2006-04-20 01:24:43] timdilbert at gmail dot com

Just out of curiousity I was wondering if this was fixed in PHP5 and
MSSQL 2005??

I haven't tried using COM just yet, but I will be when I get home (on
MSSQL 2000). But I was having the same problem with PHP5 and inserting
UTF-8 encoding into MSSQL Server 2000.

I will post if this fixed my problem. If not, I'm really sorry guys.. I
love PHP, but I might be be rebuilding my entire site is C# because
Unicode support is absolutly vital to our company and success.

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/18169

-- 
Edit this bug report at http://bugs.php.net/?id=18169&edit=1

Reply via email to