Linux安装pdo_odbc 或 pdo_dblib扩展 来支持连接sql server

2016-09-13 09:47:03   服务器

  sql server  

解决PHP5.3+ 在Linux下不支持mssql扩展问题

下载软件

unixODBC+Freetds

编译安装

tar -zxv -f unixODBC-2.3.2.tar.gz 
./configure --prefix=/usr/local/unixODBC 
make & make install

tar -zxv -f freetds-0.91.112.0.0.tar.gz 
./configure --prefix=/usr/local/freetds --with-tdsver=7.1 --enable-msdblib --enable-dbmfix --with-gnu-ld --with-unixodbc=/usr/local/unixODBC 
make & make install

配置freetds

vi freetds.conf 
[testServer] 
host = 192.168.x.x #你的SQL SERVER IP 
port = 1433 #SQL SERVER PORT 
tds version = 7.0

配置unixODBC

vi odbc.ini 
[testDSN] 
Driver = /usr/local/freetds/lib/libtdsodbc.so Description = First Test DSN Trace = No 
Servername = testServer # 这个就是FREETDS里面配置的服务器信息 
Database = test 
UID = test

编译pdo_odbc扩展(二选一)

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-odbc=unixODBC,/usr/local/unixODBC 
make & make install

如果安装了unixODBC-devel后出现如下错误: configure: error: ODBC header file '/usr/local/incl/sqlext.h' not found!

解决方案

mkdir /usr/local/incl/ 
cp /usr/include/sqlext.h /usr/local/incl/

编译pdo_dblib(二选一)

./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-dblib=/usr/local/freetds
make & make install