Linux-PHP 7.0和MSSQL(Microsoft SQL) [英] Linux - PHP 7.0 and MSSQL (Microsoft SQL)

查看:199
本文介绍了Linux-PHP 7.0和MSSQL(Microsoft SQL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我知道PHP 7.0删除了连接到MSSQL所需的扩展. FreeTDS在PHP 7.0之前是我的选择,但是对于那些仍然需要连接到MSSQL的人来说,现在确实没有明显的升级途径.

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 needing to still connect to MSSQL.

愚蠢的问题,但是考虑到MSSQL在企业环境中肯定使用得很好,我们应该如何连接到以PHP 7.0开始的那些数据库?

Stupid question, but given that MSSQL is most certainly well used in enterprise environments, how are we supposed to connect to those databases beginning with PHP 7.0?

我是忽略了一个显而易见的问题,还是PHP 7的发布基本上给需要连接到MSSQL的任何人一个耳光?

Am I overlooking something blatantly obvious or did the release of PHP 7 basically give a slap in the face to anyone needing to connect to MSSQL?

为了清楚起见,我不是谈论从运行PHP的Windows服务器进行连接,我需要从Linux服务器连接至MSSQL,因此需要Linux ODBC驱动程序.

For clarity, I am NOT talking about connecting from a Windows server running PHP, I am needing to connect to MSSQL from a Linux server and thus would need a Linux ODBC driver.

有人能免费或收费使用MSSQL 2012和PHP 7.0吗?

Does anyone make such a thing that works with MSSQL 2012 and PHP 7.0 that can be had freely or for a fee?

对我来说奇怪的是,那里没有太多的PHP 7和MSSQL信息.可以肯定的是,PHP 7是刚刚发布的,但是必须有更多的MSSQL商店(FWIW我们同时使用).

It is odd to me that there isn't much PHP 7 and MSSQL info to be had out there. Granted that PHP 7 is fresh off the presses, but there has to be more MSSQL shops out there (FWIW we use both).

推荐答案

Microsoft在PECL上具有适用于PHP 7及更高版本的SQL Server的PHP Linux驱动程序.这些已经准备好生产.要下载它们,请按照以下步骤操作:

Microsoft has PHP Linux Drivers for SQL Server for PHP 7 and above on PECL. These are production ready. To download them, follow these steps:

Ubuntu 16.04:

Ubuntu 16.04:

sudo su 
curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
exit
sudo apt-get update
sudo ACCEPT_EULA=Y apt-get install -y msodbcsql mssql-tools unixodbc-dev
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
echo "extension=sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
echo "extension=pdo_sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

CentOS 7:

sudo su
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
exit
sudo yum update
sudo ACCEPT_EULA=Y yum install -y msodbcsql mssql-tools unixODBC-devel 
sudo yum groupinstall "Development Tools"
sudo pecl install sqlsrv
sudo pecl install pdo_sqlsrv
echo "extension=sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`
echo "extension=pdo_sqlsrv" >> `php --ini | grep "Loaded Configuration" | sed -e "s|.*:\s*||"`

这将安装PHP SQL Server驱动程序并将其注册在php.ini文件夹中.

This will install the PHP SQL Server Drivers and register them in the php.ini folder.

使用以下示例验证其是否有效

Verify that it works by using the following sample

<?php
$serverName = "localhost";
$connectionOptions = array(
    "Database" => "SampleDB",
    "Uid" => "sa",
    "PWD" => "your_password"
);
//Establishes the connection
$conn = sqlsrv_connect($serverName, $connectionOptions);
if($conn)
    echo "Connected!"
?>

参考链接:

https://pecl.php.net/package/pdo_sqlsrv

https://github.com/Microsoft/msphpsql

这篇关于Linux-PHP 7.0和MSSQL(Microsoft SQL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆