安装unixODBC
yum install unixODBC-devel unixODBC freetds-devel freetds
安装pdo_odbc扩展
cd ~
cd php-7.0.1
phpize -v
./configure
出错
checking for PDO includes... checking for PDO includes... /usr/local/php7/include/php/ext
checking for selected PDO ODBC flavour... configure: error: Unknown ODBC flavour yes
include and lib dirs are looked for under 'dir'.
'flavour' can be one of: ibm-db2, iODBC, unixODBC, generic
If ',dir' part is omitted, default for the flavour
you have selected will be used. e.g.:
--with-pdo-odbc=unixODBC
will check for unixODBC under /usr/local. You may attempt
to use an otherwise unsupported driver using the "generic"
flavour. The syntax for generic ODBC support is:
--with-pdo-odbc=generic,dir,libname,ldflags,cflags
When built as 'shared' the extension filename is always pdo_odbc.so
使用
./configure --with-pdo-odbc=unixODBC,/usr/
成功
make
make install
修改php.ini
vim /usr/local/php7/etc/php.ini
添加
extension=pdo_odbc.so
在终端
php -m
重启php-fpm
kill -USR2 `cat /usr/local/php7/var/run/php-fpm.pid`
安装freetds
1、打开http://www.freetds.org/,进入到http://www.freetds.org/software.html页面.下载FreeTDS-stable.tgz
或者:
wget ftp://ftp.freetds.org/pub/freetds/current/freetds-current.tar.gz
安装很简单。步骤如下:
1.1、进入到你下载的目录然后解压。
tar -zxvf freetds-stable.tgz
1.2、cd freetds-0.91 (我目前下载的版本是0.91)
1.3、编译: ./configure --prefix=/usr/local/freetds --with-tdsver=7.1 --enable-msdblib
主要参数说明:--with-tdsver设置FreeTDS的版本,我这里设置了7.1是为了能连接SQL2005
--enable-msdblib是是否允许Microsoft数据库函数库,这里为允许;
1.4、make
1.5、make install
2、安装好之后,进行一下测试:
2.1、cd /usr/local/freetds/bin
2.2、./tsql -C
2.4、配置freetds.conf
配置freetds
cd /usr/local/freetds/lib/
vim /etc/odbcinst.ini
修改配置文件
[FreeTDS]
Description = FreeTDS ODBC Driver for SQL Server
Driver = /usr/local/freetds/lib/libtdsodbc.so.0
#Driver64 = /usr/local/freetds/lib/libtdsodbc.so
FileUsage = 1
连接代码
测试一下
$con=new \PDO('odbc:Driver=FreeTDS;Server=X.X.X.X;Port=1433;Database=MJDataBase;Tds_version=7.2;Client_charset=UTF-8;Uid=sa;Pwd=sa;');
var_dump($con);