1.安装FreeTDS
wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-patched.tar.gz
tar -zxvf freetds-patched.tar.gz
ll
# drwxr-xr-x 10 root root 4096 Apr 3 17:16 freetds-1.00.84
# -rw-r--r-- 1 root root 2913320 Apr 3 17:07 freetds-patched.tar.gz
cd freetds-1.00.84
[root@iztkatyiq1z1ltz freetds-1.00.84]# ll
total 2284
-rw-r--r-- 1 11027 11027 137693 Apr 2 17:00 aclocal.m4
-rw-r--r-- 1 11027 11027 2772 May 19 2016 AUTHORS
-rwxr-xr-x 1 11027 11027 1576 May 6 2015 autogen.sh
-rw-r--r-- 1 11027 11027 309 May 19 2016 BUGS
-rw-r--r-- 1 11027 11027 23345 Apr 2 17:00 ChangeLog
-rw-r--r-- 1 11027 11027 14760 Jun 9 2017 CMakeLists.txt
-rwxr-xr-x 1 11027 11027 7333 Apr 2 17:00 compile
-rwxr-xr-x 1 11027 11027 43940 Apr 2 17:00 config.guess
-rw-r--r-- 1 root root 272543 Apr 3 17:15 config.log
-rwxr-xr-x 1 11027 11027 18343 May 15 2015 config.rpath
-rwxr-xr-x 1 root root 72697 Apr 3 17:15 config.status
-rwxr-xr-x 1 11027 11027 36383 Apr 2 17:00 config.sub
-rwxr-xr-x 1 11027 11027 689741 Apr 2 17:00 configure
-rw-r--r-- 1 11027 11027 30429 Apr 2 17:00 configure.ac
-rw-r--r-- 1 11027 11027 18092 May 19 2016 COPYING
-rw-r--r-- 1 11027 11027 25383 May 19 2016 COPYING.LIB
-rwxr-xr-x 1 11027 11027 23566 Apr 2 17:00 depcomp
drwxr-xr-x 5 root root 4096 Apr 3 17:16 doc
-rw-r--r-- 1 11027 11027 1281 Feb 5 2017 freetds.conf
-rw-r--r-- 1 root root 4368 Apr 3 17:15 freetds.spec
-rw-r--r-- 1 11027 11027 4372 May 19 2016 freetds.spec.in
drwxr-xr-x 4 root root 4096 Apr 3 17:15 include
-rw-r--r-- 1 11027 11027 756 May 19 2016 INSTALL
-rwxr-xr-x 1 11027 11027 6760 Apr 2 17:00 install-sh
-rw-r--r-- 1 11027 11027 2359 May 6 2015 interfaces
-rwxr-xr-x 1 root root 342693 Apr 3 17:15 libtool
-rw-r--r-- 1 11027 11027 370 May 6 2015 locales.conf
-rw-r--r-- 1 11027 11027 324089 Apr 2 17:00 ltmain.sh
drwxr-xr-x 2 root root 4096 Apr 3 17:10 m4
-rw-r--r-- 1 root root 28983 Apr 3 17:15 Makefile
-rw-r--r-- 1 11027 11027 2031 May 19 2016 Makefile.am
-rw-r--r-- 1 11027 11027 29364 Apr 2 17:00 Makefile.in
drwxr-xr-x 2 root root 4096 Apr 3 17:15 misc
-rwxr-xr-x 1 11027 11027 6872 Apr 2 17:00 missing
-rwxr-xr-x 1 11027 11027 729 Sep 23 2015 mkinstalldirs
-rw-r--r-- 1 11027 11027 24295 May 19 2016 NEWS
-rw-r--r-- 1 root root 762 Apr 3 17:16 PWD
-rw-r--r-- 1 11027 11027 762 May 6 2015 PWD.in
-rw-r--r-- 1 11027 11027 3081 May 19 2016 README
drwxr-xr-x 2 root root 4096 Apr 3 17:16 samples
drwxr-xr-x 10 root root 4096 Apr 3 17:15 src
-rw-r--r-- 1 11027 11027 828 May 19 2016 tds.dox
-rwxr-xr-x 1 11027 11027 4640 Apr 2 17:00 test-driver
-rw-r--r-- 1 11027 11027 1048 May 19 2016 Thanks-1.0
-rw-r--r-- 1 11027 11027 5813 May 19 2016 TODO
drwxr-xr-x 2 root root 4096 Apr 3 17:15 vms
drwxr-xr-x 3 root root 4096 Apr 3 17:15 win32
[root@iztkatyiq1z1ltz freetds-1.00.84]#
sqlsever2008 with-tdsver 要等于 7.3
./configure --prefix=/usr/local/freetds --with-tdsver=7.3 --enable-msdblib
make && make install
配置FreeTDS
# cd ../
# echo "/usr/local/freetds/lib/" > /etc/ld.so.conf.d/freetds.conf
# ldconfig
验证FreeTDS版本
这一步非常重要,通过才可以继续,不然后面的步骤都是无意义的。
首先看看版本信息
# /usr/local/freetds/bin/tsql -C
Compile-time settings (established with the "configure" script)
Version: freetds v1.00.84
freetds.conf directory: /usr/local/freetds/etc
MS db-lib source compatibility: yes
Sybase binary compatibility: no
Thread safety: yes
iconv library: yes
TDS version: 7.3
iODBC: no
unixodbc: no
SSPI "trusted" logins: no
Kerberos: no
OpenSSL: yes
GnuTLS: no
MARS: no
测试数据库是否联通
/usr/local/freetds/bin/tsql -H 数据库服务器IP -p 端口号 -U 用户名 -P 密码
[root@iztkatyiq1z1ltz freetds-1.00.84]# /usr/local/freetds/bin/tsql -H 111.2xx.2xx.2xx -p 56xx -U xxx -P xxx
locale is "en_US.UTF-8"
locale charset is "UTF-8"
using
添加PHP扩展pdo的pdo_dblib
1.确定phpize是否可用
[root@iztkatyiq1z1ltz freetds-1.00.84]# phpize -v
Configuring for:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
如果报没有phpize该命令的话可以尝试用php的全路径 如wdcp php 5.6
/www/wdlinux/phps/56/bin/phpize -v
2.下载 php5.6包到dblib文件下
wget hk2.php.net/distributions/php-5.6.35.tar.bz2
tar jxvf php-5.6.35.tar.bz2
cd php-5.6.35/ext/pdo_dblib/
3.执行phpize
/www/wdlinux/phps/56/bin/phpize
如果报Cannot find config.m4错误请看有pdo_dblib没有config.m4文件。如果没有cp一份里面带.m4的文件重命名为config.m4 然后再/www/wdlinux/phps/56/bin/phpize
./configure --with-php-config=/www/wdlinux/phps/56/bin/php-config --with-pdo-dblib=/usr/local/freetds/
/www/wdlinux/phps/56/bin/php-config必须是要修改php.ini所对应的php-config
make && make install
4.在对应的php.ini里面添加配置
extension = pdo_dblib.so
5.重启php
6.phpinfo()
出现pdo_dblib配置就完成配置了
7.php连接代码 private function linksever(){ header("content-type:text/html;charset=utf-8");
try{
if(PATH_SEPARATOR==':'){
$db = new \PDO("dblib:host=111.xxx.xxx.xxx:56xx;dbname=","usenamexxx","pwdxxx");
}else{
$db = new \PDO("sqlsrv:Server=111.xxx.xxx.xxx,56xx;Database=xxx","usenamexxx","pwdxxx");
}
}catch(PDOException $e){
echo "ERROR:".$e->getMessage();
exit;
}
//if($db)echo "OK!Connected!<br />";
return $db;
}