php连接sqlserver

参考:https://www.bt.cn/bbs/forum.php?mod=viewthread&tid=72329&highlight=sqlsrv


curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo
yum clean all
ACCEPT_EULA=Y yum install -y msodbcsql mssql-tools unixODBC-devel
#安装sqlsrv
cd /tmp
wget https://pecl.php.net/get/sqlsrv-5.8.1.tgz
tar -zxvf sqlsrv-5.8.1.tgz
cd sqlsrv-5.8.1
/www/server/php/73/bin/phpize
./configure --with-php-config=/www/server/php/73/bin/php-config
make && make install
echo "extension = sqlsrv.so" >> /www/server/php/73/etc/php.ini

#安装pdo_sqlsrv
cd /tmp
wget https://pecl.php.net/get/pdo_sqlsrv-5.8.1.tgz
tar -zxvf pdo_sqlsrv-5.8.1.tgz
cd pdo_sqlsrv-5.8.1
/www/server/php/73/bin/phpize
./configure --with-php-config=/www/server/php/73/bin/php-config
make && make install
echo "extension=pdo_sqlsrv.so" >> /www/server/php/73/etc/php.ini



/etc/init.d/php-fpm-73 reload

#检查扩展是否安装成功
/www/server/php/73/bin/php -m|grep -i  sqlsrv







=================================

php连接sqlserver


1、安装必要的软件包:
sudo yum install epel-release
sudo yum install unixODBC-devel

2、下载并安装 Microsoft 提供的 SQL Server 驱动程序:
curl https://packages.microsoft.com/config/rhel/7/prod.repo > /etc/yum.repos.d/mssql-release.repo

yum remove unixODBC-utf16 unixODBC-utf16-devel

ACCEPT_EULA=Y yum install msodbcsql17

ACCEPT_EULA=Y yum install mssql-tools

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile

echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc

source ~/.bashrc

yum install unixODBC-devel


cat /etc/odbcinst.ini

可以看到最后面有[ODBC Driver 17 for SQL Server]的配置,恭喜你,驱动安装完成
参考:https://cloud.tencent.com/developer/article/2006009

也可以使用下面命令验证是否成功:
odbcinst -q -d -n "ODBC Driver 17 for SQL Server"

如果成功安装,您应该能够看到有关驱动程序的详细信息。


3、启用 PHP 的 SQL Server 扩展:
sudo yum install php-pdo
sudo yum install php-sqlsrv



4、编辑 php.ini 文件:打开 PHP 的配置文件 php.ini,找到以下两行并确保它们未被注释:
extension=pdo_sqlsrv
extension=sqlsrv


重启服务器,测试php连接SQLserver是否正常