How to Use freetds to connect to mssql in Linux

Source: Internet
Author: User
In the case of php5.3, The dblib driver of pdo cannot connect to mssql. According to the official description, 5.2 has modified this bug, but 5.3 does not. You can use the mssql function provided by php.

In the case of php5.3, The dblib driver of pdo cannot connect to mssql. According to the official description, 5.2 has modified this bug, but 5.3 does not. You can use the mssql function provided by php.

In the case of php5.3, The dblib driver of pdo cannot connect to mssql. According to the official description, 5.2 has modified this bug, but 5.3 does not.

You can use the mssql function that comes with php. Compile freetds, php_mssql, and pdo_dblib 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/

The character set cannot be set with the built-in mssql function, and set names is not supported. Finally, I referred to the adodb code and found that com or ative mssql driver must be used to solve this problem, these two things can be used in windows, but linux is not very good. The solution is to edit/usr/local/freetds/etc/freetds. conf.
Adding a client charset = GBK and setting it to UTF-8 is incorrect, because the mssql sorting rule database is set to Chinese PRC by default, which is equivalent to gb2312,

In addition, mssql. charset in php. ini does not need to be set. In fact, it is clear:
; Specify client character set.
; If empty or not set the client charset from freetds. comf is used
; This is only used when compiled with FreeTDS

This parameter is required only when the FreeTDS client charset is null or is not set. If the character is incorrectly set to UTF-8, And the FreeTDS client charset is also set to utf8, an error is reported when mssql_connect is returned. In the final conclusion, you only need to set the FreeTDS client charset to GBK, and then in the php program iconv ('gbk', 'utf-8 // IGNORE ', $ str ); everything is normal.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.