none
sqlsrv_connect charset problem

    Question

  • i will connect mssql with php by sqlsrv_connect, but can't display chinese.

    the sqlsrv_connect can set the charset, like the COM object?

    $link = new COM("ADODB.Connection", NULL, CP_UTF8);

     

    $serverName = "db_server";
    $connectionInfo = array( "Database"=>"db_name", "UID" => "db_username", "PWD" => "db_password");
    $conn = sqlsrv_connect( $serverName, $connectionInfo );

     

    the $connectionInfo array can set the charset?

     

    thx~

    Monday, October 27, 2008 3:32 AM

Answers

  • Ivan,

     

    There is no connection option to specify the character set.

     

    If the data is stored in an nchar/nvarchar column in the database, you should be able to retrieve the data and then convert it to UTF-8 using the pattern shown in the driver documentation here:

        http://msdn.microsoft.com/en-us/library/cc626307(SQL.90).aspx

     

    David Sceppa

    Program Manager - Microsoft SQL Server Driver for PHP

    Tuesday, November 4, 2008 12:50 AM

All replies

  • Ivan,

     

    There is no connection option to specify the character set.

     

    If the data is stored in an nchar/nvarchar column in the database, you should be able to retrieve the data and then convert it to UTF-8 using the pattern shown in the driver documentation here:

        http://msdn.microsoft.com/en-us/library/cc626307(SQL.90).aspx

     

    David Sceppa

    Program Manager - Microsoft SQL Server Driver for PHP

    Tuesday, November 4, 2008 12:50 AM
  • The steps you have shown on the document is not convenient...
    At least, charset conversion is done by driver, not handled by application logic. It is hard to maintenance if there are this kind of adjustor codes all around the code.

    And not all the sql statements have the placeholders. If the sql statement is the simple string (means no placeholders) and it has some multibyte characters, no way to convert the statement which can be accepted by the driver. 
    I'm sure a lot of applications send the sql statements by this way.

    I hope we can specify the charset as the connection option.

    Monday, November 17, 2008 8:38 AM