天天看點

php同時連接配接mssql和mysql

前幾天研究了怎麼讓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中添加

        host = IP

        port = port

        tds version = 8.0

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

途中還遇到找不到libmysqlclient.so的問題,在/usr/lib下建立一個連結指向/usr/lib/mysql/libmysqlclient.so.15.0.0即可解決。

4.測試

測試程式是我們的php程式員寫的,就不發出來了。

本文轉自 sharkyan 51CTO部落格,原文連結:http://blog.51cto.com/sharkyan/288485,如需轉載請自行聯系原作者