zoukankan      html  css  js  c++  java
  • php7 安装mssql 扩展

    一、 Install the Microsoft PHP Drivers for SQL Server

    [root@w91 source]#curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
    [root@w91 source]# yum install -y msodbcsql mssql-tools unixODBC-devel
    [root@w91 source]# yum -y install php-pear php7.0-dev
    
    #下面如果安装失败下载后安装即可 
    [root@w91 source]# pecl install sqlsrv 
    [root@w91 source]# pecl install pdo_sqlsrv
    #下载地址
    [root@w91 source]# wget http://pecl.php.net/get/sqlsrv-5.2.0.tgz
    [root@w91 source]# wget http://pecl.php.net/get/pdo_sqlsrv-5.3.0.tgz

    执行到第二条时出现问题:

    解决方式:

    安装c++11 gcc4.8.x

    [root@w91 home]wget http://people.centos.org/tru/devtools-2/devtools-2.repo -O /etc/yum.repos.d/devtools-2.repo 
    [root@w91 home]yum install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
    [root@w91 home]yum install devtoolset-2-gcc-gfortran 
    [root@w91 home]yum install devtoolset-2-binutils-devel
    [root@w91 source]# ln -s /opt/rh/devtoolset-2/root/usr/bin/* /usr/local/bin/
    [root@w91 source]# mv /usr/local/bin/sudo{,_bak}
    [root@w91 source]# hash -r 
    [root@w91 source]#gcc --version
    gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-15)
    Copyright (C) 2013 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    

      

    再次执行

    [root@w91 source]# pecl install sqlsrv
    [root@w91 source]# pecl install pdo_sqlsrv
    

    测试连接

    <?php
    $serverName = "192.168.10.20";
    $connectionOptions = array(
        "Database" => "db_fidfe",
        "Uid" => "sea",
        "PWD" => "12456M"
    );
    //Establishes the connection
    $conn = sqlsrv_connect($serverName, $connectionOptions);
    //Select Query
    $tsql= "SELECT @@Version as SQL_VERSION";
    //Executes the query
    $getResults= sqlsrv_query($conn, $tsql);
    //Error handling
     
    if ($getResults == FALSE)
        die(FormatErrors(sqlsrv_errors()));
    ?> 
     <h1> Results : </h1>
     <?php
    while ($row = sqlsrv_fetch_array($getResults, SQLSRV_FETCH_ASSOC)) {
        echo ($row['SQL_VERSION']);
        echo ("<br/>");
    }
    sqlsrv_free_stmt($getResults);
    function FormatErrors( $errors )  
    {  
        /* Display errors. */  
        echo "Error information: <br/>";  
      
        foreach ( $errors as $error )  
        {  
            echo "SQLSTATE: ".$error['SQLSTATE']."<br/>";  
            echo "Code: ".$error['code']."<br/>";  
            echo "Message: ".$error['message']."<br/>";  
        }  
    }  
    ?>

    附带网上两个centos6、7安装php7 的mssql扩展

    CentOS 6
    curl https://packages.microsoft.com/config/rhel/6/prod.repo > /etc/yum.repos.d/mssql-release.repo
    yum clean all
    yum update -y
    ACCEPT_EULA=Y yum install -y msodbcsql mssql-tools unixODBC-devel 
    cd /usr/local/src
    rm -rf sqlsrv* pdo*
    wget https://pecl.php.net/get/sqlsrv-4.3.0.tgz
    tar -zxvf sqlsrv-4.3.0.tgz
    cd sqlsrv-4.3.0
    phpize
    ./configure
    make
    make install
    echo ""
    grep "sqlsrv.so" /usr/local/php/php.ini || echo "extension=sqlsrv.so" >> /usr/local/php/php.ini
    cd /usr/local/src
    wget https://pecl.php.net/get/pdo_sqlsrv-4.3.0.tgz
    tar -zxvf pdo_sqlsrv-4.3.0.tgz
    cd pdo_sqlsrv-4.3.0
    phpize
    ./configure
    make
    make install
    echo ""
    grep "pdo_sqlsrv.so" /usr/local/php/php.ini || echo "extension=pdo_sqlsrv.so" >> /usr/local/php/php.ini
    rm -rf sqlsrv* pdo*
    

    CentOS 7

    curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
    yum clean all
    yum update -y
    ACCEPT_EULA=Y yum install -y msodbcsql mssql-tools unixODBC-devel 
    cd /usr/local/src
    rm -rf sqlsrv* pdo*
    wget https://pecl.php.net/get/sqlsrv-4.3.0.tgz
    tar -zxvf sqlsrv-4.3.0.tgz
    cd sqlsrv-4.3.0
    phpize
    ./configure
    make
    make install
    echo ""
    grep "sqlsrv.so" /usr/local/php/php.ini || echo "extension=sqlsrv.so" >> /usr/local/php/php.ini
    cd /usr/local/src
    wget https://pecl.php.net/get/pdo_sqlsrv-4.3.0.tgz
    tar -zxvf pdo_sqlsrv-4.3.0.tgz
    cd pdo_sqlsrv-4.3.0
    phpize
    ./configure
    make
    make install
    echo ""
    grep "pdo_sqlsrv.so" /usr/local/php/php.ini || echo "extension=pdo_sqlsrv.so" >> /usr/local/php/php.ini
    rm -rf sqlsrv* pdo*
    

      

  • 相关阅读:
    IIS7 配置PHP服务器
    WebAPI Post请求多参数处理方案
    Mssql 跨域查询
    sql 给数据库表 字段 添加注释
    log4net配置文件
    搭建svn服务器小结
    Django测试开发-30- xadmin模板中class Meta:和def __str__(self):的应用
    Django测试开发-29- xadmin模板中详情页面布局form_layout详解
    Django测试开发-28- xadmin模板中related_name和_set()用法
    Django测试开发-27- xadmin模板中注册增加Student和Teacher,Card及CardDetail表
  • 原文地址:https://www.cnblogs.com/xzlive/p/9187838.html
Copyright © 2011-2022 走看看