前几天研究了怎么让php同时连接mssql和mysql,让然还是因为有需求了。
 
网上google了一下发现真是晕啊,能用--with-mssql  --with-pdo-dblib这两个编译选项做,还需要freeTDS和unixODBC。
不过php的pdo好像还在测试阶段就放弃了--with-pdo-dblib这个方法了。
 
下面是我经验分享。
 
1.装unixODBC
#yum install unixODBC*
在odbcinst.ini中添加,或用图形界面配置。
[sql2k5]
Description = v0.64 with Protocol v8.0
Driver = /usr/local/lib/libtdsodbc.so
Driver64 = /usr/local/lib/libtdsodbc.so
Setup = /usr/lib/libtdsS.so
Setup64 = /usr/lib/libtdsS.so
UsageCount = 1
CPTimeout =
CPReuse =
在odbc.ini中添加,或用图形界面配置。
[mssql]
Description = sql2k5
Driver = sql2k5
Servername = sql2k5
#google来的信息说面这里不要设置IP地址什么的,要和freeTDS.conf里的设置一样。
Database =
UID = username
PWD = passwd
Port = port
 
2.装freeTDS
#./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib
#make && make install
在/etc/bashrc中加入export PATH="$PATH:/usr/local/freetds/bin"。/etc/profile中也行。
#echo "/usr/local/freetds/lib" >> /etc/ld.so.conf
#ldconfig
在freetds.conf中添加
[sql2k5]
        host = IP
        port = port
        tds version = 8.0
freeTDS和unixODBC的配置参考链接: http://rickyfang.blog.51cto.com/1213/125837
 
3.装php
#./configure --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-apxs2=/usr/sbin/apxs --with-bz2 --enable-zip --with-curl --enable-ftp --with-gd --with-pic --with-jpeg-dir --with-png-dir --with-zlib --with-mhash --with-mcrypt --enable-mbstring --without-pear --with-libxml-dir=/usr --enable-xml --with-curl --enable-soap --with-ldap --with-ldap-sasl --with-xmlrpc --enable-pcntl --with-openssl --enable-bcmath --enable-shmop --enable-sysvsem --with-mssql=/usr/local/freetds --with-mysql=/var/lib/mysql
由于开发环境需要php有很多功能所以编译选项比较复杂,如果编译过程中提示缺少东西的话,用yum装就行了。
我的安装过程中提示没有libmycrypt,yum也不行,所以又编译安装了libmycrypt。
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8/
./configure
make
make install
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
参考链接: http://blog.s135.com/nginx_php_v6/
途中还遇到找不到libmysqlclient.so的问题,在/usr/lib下创建一个链接指向/usr/lib/mysql/libmysqlclient.so.15.0.0即可解决。
4.测试
测试程序是我们的php程序员写的,就不发出来了。