Connecting PHP / PDO and SQL Server and i18n

In our web application, we use PHP5.2.6 + PDO to connect to the SQL Server 2005 database and store Russian texts.

Database mapping Cyrillic_General_CI_AS, table sorting Cyrillic_General_CI_AS, column type NVARCHAR(MAX).

We tried to connect to the database using the following two schemes causing different problems.

  • PDO mssql:

    $dbh = new PDO ('mssql:host='.$mssql_server.';dbname='.$mssql_db, $mssql_login, $mssql_pwd);
    

    in this case, the result of a simple query:

    SELECT field1 FROM tbl1 WHERE id=1
    

    shows field1data truncated to 255 bytes.

  • PDO odbc:

    $dbh = new PDO ('odbc:DSN=myDSN;UID='.$mssql_login.';PWD='.$mssql_pwd);
    

    and in this case, the result of the same query shows complete, not truncated data, but with question marks instead of Russian characters.


Notes:

  • In SQL Management Studio, data is not truncated, and Russian characters are also displayed correctly.
  • We have Windows 2003 Enterprise Edition SP2

, ?

+5
5

SET NAMES "charset" .

, Cyrillic_General_CI_AS, ""?

+2

, NVARCHAR MSSQL:

$_ = iconv('Windows-1252', 'UTF-8', $_);
+1

utf8_general_ci - , - .

MySQL PostgreSql - SQL Server.

DSN - .

!

0

PDO, FreeTDS - mssql_ *. , PDO . PHP 5.1.2, FreeTDS mssql.charset-option.

0

: SQL Server 2005 PHP 5.x PDO. nvarchar (MAX) nvarchar (255), . , ODBC PDO MS SQL. varchar, .

0

All Articles