Linux - PHP 7.0 and MSSQL (Microsoft SQL)

后端 未结 9 1029
夕颜
夕颜 2020-12-02 09:08

Yes, I know that PHP 7.0 removed the extensions needed to connect to MSSQL. FreeTDS was my option prior to PHP 7.0 but now there really is no obvious upgrade path for those

相关标签:
9条回答
  • 2020-12-02 09:15

    I modified

    yum install freetds-dev
    vim /etc/freetds.conf
    

    And modify freetds.conf, install php mssql module

    yum install php-mssql.x86_64
    
    0 讨论(0)
  • 2020-12-02 09:17

    The sybase of PHP7 contains the pdo_dblib module.

    sudo apt install php7.0-sybase
    
    0 讨论(0)
  • 2020-12-02 09:18

    Official MS extension has branch for PHP 7:

    • https://github.com/Azure/msphpsql/tree/PHP-7.0 (Windows)
    • https://github.com/Microsoft/msphpsql/tree/PHP-7.0-Linux

    There's still lot of things missing, some marked as planned (Linux support is amongst them), nevertheless it could be another solution in the future.

    EDIT (09-09-2016): There were already few Linux releases published since March, with CentOS/Ubuntu specific packages and source available. Keep in mind they aren't marked as Production Ready yet.

    0 讨论(0)
  • 2020-12-02 09:20
    sudo apt-get install php7.2-pdo-dblib
    

    this worked for me on PHP 7.0 but still, you need to add the extension on

    /etc/php/7.0/apache2/php.ini

    as well as

    /etc/php/7.0/cli/php.ini

    0 讨论(0)
  • 2020-12-02 09:29

    I definitely agree with you. I work primarily with SQL Servers at work and do not understand why they are not including default drivers for SQL servers in PHP.

    For linux, i'm not too sure what you previously used but I found that the "dblib" driver is the best driver to connect to SQL Servers.

    But basically for a linux box you just want to run these few steps to have a sql server driver installed.

    apt-get install freetds-dev -y
    vim /etc/freetds.conf
    

    Then go ahead and add your connections there and restart apache and you should be good to go!

    0 讨论(0)
  • 2020-12-02 09:35

    As per the answer above - the steps output a shared object (*.so) so the php.ini file needs the file extension too.

    echo "extension=sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
    echo "extension=pdo_sqlsrv.so" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
    
    0 讨论(0)
提交回复
热议问题