php5.3 case, with PDO Dblib driver can not connect MSSQL, according to the official description, 5.2 has modified this bug,5.3 No.
It is possible to use the MSSQL function that comes with PHP. Compile the Freetds,php_mssql,pdo_dblib parameters as follows:
./configure--prefix=/usr/local/freetds--with-tdsver=8.0--enable-msdblib
./configure--with-php-config=/usr/local/php/bin/php-config--with-mssql=/usr/local/freetds/
./configure--with-php-config=/usr/local/php/bin/php-config--with-mssql=/usr/local/freetds--enable-pdo-- with-pdo-dblib=/usr/local/freetds/
With the MSSQL function can not set the charset, set names is not supported, the last reference to ADODB code, found to solve the problem also need to use COM, or with ative MSSQL driver, these two things under Windows can, Linux is not very good. The solution is to edit the/usr/local/freetds/etc/freetds.conf
Add a line of client CharSet = GBK, set to Utf-8 is wrong, because the MSSQL collation database default setting is Chinese PRC, equivalent to gb2312,
In addition php.ini inside Mssql.charset is not need to set, actually said very clearly:
; Specify client character set.
; If empty or not set the client charset from FREETDS.COMF is used
; This was only used when compiled with FreeTDS
This is required when FreeTDS's client charset is empty or not set. Once the wrong to set up here to Utf-8,freetds client CharSet also set to UTF8, the result mssql_connect when the error began. The final conclusion, only need to set FreeTDS client CharSet for GBK, and then inside the PHP program iconv (' GBK ', ' Utf-8//ignore ', $str);
The problem of using FreeTDS to connect MSSQL Chinese garbled in Linux "reference 2"