linux下 链接 sqlserver数据库 驱动的安装

1.必需安装freetds 

安装pdo_dblib扩展首先需要安装freetds。

freeTDS的最新稳定版是0.91,这个可以在官网上下载http://www.freetds.org/ ,也可以在http://download.csdn.net/detail/DLUTXIE/3663528下载

下载freetds

wget  ftp://ftp.freetds.org/pub/freetds/stable/freetds-stable.tgz

tar zxf freetds-stable.tgz

cd freetds-stable/

/usr/bin/phpzie

./configure --prefix=/usr/local/freetds --with-tdsver=8.0 --enable-msdblib

make  && make install 

配置freetds配置文件:

Host填sqlserver服务器地址

Port 填端口

Tds version=8.0

Client charset = utf8

3.安装php_dblib模块

    /usr/local /php5/bin/phpize 

通过pdo_dblib链接数据库

--with-pdo-dblib路径指的是freetds的安装路径

    ./configure --with-php-config=/usr/local/php5/bin/php-config  --with-pdo-dblib=/usr/local/freetds

 make

 make install 

在php.ini里加上extension=pdo_dblib.so。

然后重启nginx和php-fpm

[root@iZ25ns61s3yZ no-debug-non-zts-20121212]# /etc/init.d/nginx restart

[root@iZ25ns61s3yZ no-debug-non-zts-20121212]# /etc/init.d/php-fpm restart

查看phpinfo里是否存在pdo_dblib扩展

4.pdo连接数据库的时候:

         记得是用dblib,而不是sqlserver

<?php

    try{

            $link=new PDO("dblib:host=souyue91;dbname=dbname","dbuser","dbpass");

    }catch(PDOException $e){

        echo $e->getMessage();

    }

Host填的是freetds里面配的souyue91

原文地址:https://www.cnblogs.com/jiechn/p/4841865.html