当前位置: 首页 > 工具软件 > PHP SQLView > 使用案例 >

(docker)php容器中装sqlserver扩展

章玮
2023-12-01

安装Microsoft ODBC Driver for SQL Server 驱动
参考网址:https://docs.microsoft.com/zh-cn/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-ver15

根据个人实际操作系统找到对应操作系统对应版本按指示安装执行即可

curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
出现 gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation 
这个错误,执行apt-get update && apt-get install -y gnupg2 即可

#Download appropriate package for the OS version
#Choose only ONE of the following, corresponding to your OS version

#Debian 8
curl https://packages.microsoft.com/config/debian/8/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Debian 9
curl https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list

#Debian 10
curl https://packages.microsoft.com/config/debian/10/prod.list > /etc/apt/sources.list.d/mssql-release.list

exit
apt-get update
ACCEPT_EULA=Y apt-get install msodbcsql17
# optional: for bcp and sqlcmd
ACCEPT_EULA=Y apt-get install mssql-tools
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bash_profile
echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc
source ~/.bashrc
# optional: for unixODBC development headers
apt-get install unixodbc-dev
# optional: kerberos library for debian-slim distributions
apt-get install libgssapi-krb5-2

安装sqlServer php扩展
我们通过docker-php-ext-install安装扩展


 1. apt-get -y install unixodbc-dev
 2. pecl install sqlsrv-5.9.0 && pecl install pdo_sqlsrv-5.9.0
 3. tar zxvf sqlsrv-5.9.0.tgz && tar zxvf pdo_sqlsrv-5.9.0.tgz
 4. mv sqlsrv-5.9.0 /usr/src/php/ext/sqlsrv && mv pdo_sqlsrv-5.9.0 /usr/src/php/ext/pdo_sqlsrv
 6. docker-php-ext-install sqlsrv && docker-php-ext-install pdo_sqlsrv

php连接sqlserver出现了一个
SQLSTATE[08001]: [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: [error:1425F102:SSL routines:ssl_choose_client_version:unsupported protocol]

查了资料以后,发现Debian现在至少需要TLS 1.2版本而不是TLS 1.0版本。如果另一端不支持TLS 1.2或更高版本,则将出现一些连接错误。

建议将服务器上的openvpn升级到支持TLS 1.2的较新版本
因为我连接的服务器比较老,我选择了将MinProcotol修改为TLSv1(修改TLSv1.1还是报原来那个错误)。

vim /etc/ssl/openssl.cnf
在文件末尾有:
[system_default_sect]
MinProtocol = TLSv1.2 #这里改成TLSV1
CipherString = DEFAULT@SECLEVEL=2

————————————————
参考:https://blog.csdn.net/weixin_55219956/article/details/113752981

 类似资料: