逍遥乘风:Linux(centos)下PHP支持MSSQL实例教程
PHP已经安装完毕,需要再加一个mssql支持功能:
FreeTDS 下载地址:http://www.filewatcher.com/m/freetds-0.82.tar.gz.1596755.0.0.html 当前版本0.82
1. 编译FreeTDS
# tar zxvf freetds-0.82.tar.gz
# cd freetds-0.82
//--with-tdsver=8.0是指安装tds 8.0版本(如果没有加这个参数,则按照默认编译为5.0。5.0连接数据库的端口是4000,而不是SQLServer的1433)
# ./configure --prefix=/usr/local/freetds --with-tdsver=8.0
# make
# make install
2. 编译PHP
要增加对MSSQL的支持,只要在编译参数上加上
–with-mssql=/usr/local/freetds
即可。
# ./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/etc/cgi –with-mysql=/usr/local/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-iconv-dir=/usr/local –with-freetype-dir=/usr –with-jpeg-dir=/usr –with-png-dir=/usr –with-zlib –with-libxml-dir=/usr –with-xmlrpc –enable-xml –enable-mbstring –enable-ftp –with-gd –enable-magic-quotes –with-pear –enable-sockets –with-ttf –enable-gd-native-ttf –enable-sysvsem –enable-sysvshm –enable-shmop –enable-force-cgi-redirect –enable-fastcgi –enable-zip –enable-fpm –with-mhash –with-mcrypt –enable-discard-path –enable-bcmath –enable-inline-optimization –with-curl –with-curlwrappers –enable-mbregex –with-openssl --with-mssql=/usr/local/freetds
3. 中文问题
一种是(本例中采用的方式):
# vim /usr/local/php/lib/php.ini
mssql.charset = “GBK”
另外一种:(没有测试)
vi /usr/local/freetds/etc/freetds.conf
增加一行:
#解决中文乱码问题
client charset=utf8
保存退出即可。
4. 测试一下MSSQL的连接
# /usr/local/freetds/bin/tsql -H 10.10.10.11 -p 1433 -U 用户名 -P 密码
1> use test
2> go
1> select * from test
2> go
1> quit
运行成功后则完事大吉。