Linux下PHP连接SQL SERVER

1、编译安装FreeTDS
wget ftp://ftp.ibiblio.org/pub/Linux/ALPHA/freetds/stable/freetds-stable.tgz
tar zxvf freetds-stable.tgz
cd freetds-0.82/
./configure –prefix=/usr/local/freetds –with-tdsver=8.0 –enable-msdblib
make && make install
cd ../
echo “/usr/local/freetds/lib/” > /etc/ld.so.conf.d/freetds.conf
ln -s /usr/local/freetds/lib/libsybdb.so.5.0.0 /usr/local/freetds/lib/libsybdb.so.4
/sbin/ldconfig
rm -f /usr/local/freetds/etc/freetds.conf
vi /usr/local/freetds/etc/freetds.conf
[global]
        # TDS protocol version
;       tds version = 4.2
        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff
        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10
        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting ‘text size’ to a more reasonable limit
        text size = 64512
        host = mssql.yourdomain.com
        port = 1433
        tds version = 8.0
        client charset = UTF-8
2、编译安装PHP自带MSSQL扩展
进入本地已存在的php-5.2.XX源码包目录:
cd /software/php-5.2.XX/ext/mssql/
/usr/local/php/bin/phpize
./configure –with-php-config=/usr/local/php/bin/php-config –with-mssql=/usr/local/freetds/
如果出现如下报错:
configure: error: Directory /usr/local/freetds is not a FreeTDS installation directory
PHP检测其安装目录的时候有些问题,检查依据是两个已经不用的文件,创建两个空文件就OK
touch /usr/local/freetds/include/tds.h
touch /usr/local/freetds/lib/libtds.a

make && make install
3、在php.ini配置文件中增加mssql.so
vi /usr/local/php/etc/php.ini(根据你的php.ini路径修改)
extension = “mssql.so”
4、重启apache

此条目发表在Php分类目录,贴了, 标签。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注