配置php7连接SQLSERVER数据库

安装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);

转载于:https://my.oschina.net/shanpeng921/blog/1632901

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值