debian安装mssql支持库
官网
https://github.com/Microsoft/msphpsql
php环境
https://pecl.php.net/packages.php?catpid=7&catname=Database
pear/pecl环境
官网
兼容性
具体请看:https://learn.microsoft.com/en-us/sql/connect/odbc/windows/system-requirements-installation-and-driver-files?view=sql-server-ver16#sql-version-compatibility 简单来说: SQL2008-2017用:odbc13版本 SQL2012-2022用:odbc17版本
debian12 安装odbc17版本
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | sudo gpg --dearmor -o /usr/share/keyrings/microsoft-prod.gpg curl https://packages.microsoft.com/config/debian/12/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list apt-get update ACCEPT_EULA=Y apt-get install -y msodbcsql17 ACCEPT_EULA=Y apt-get install -y mssql-tools echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc apt-get install -y unixodbc-dev apt-get install -y libgssapi-krb5-2
debian11 安装odbc17版本
curl https://packages.microsoft.com/keys/microsoft.asc | sudo tee /etc/apt/trusted.gpg.d/microsoft.asc curl https://packages.microsoft.com/config/debian/11/prod.list | sudo tee /etc/apt/sources.list.d/mssql-release.list apt-get update ACCEPT_EULA=Y apt-get install -y msodbcsql17 ACCEPT_EULA=Y apt-get install -y mssql-tools echo 'export PATH="$PATH:/opt/mssql-tools/bin"' >> ~/.bashrc source ~/.bashrc apt-get install -y unixodbc-dev apt-get install -y libgssapi-krb5-2
PHP安装扩展
推荐使用pecl安装,详见:http://pear.php.net
pecl install sqlsrv pdo_sqlsrv
修改php.ini文件,加入扩展。如果不知道php.ini在什么地方,可执行:php --ini
查看配置文件路径
extension=sqlsrv.so extension=pdo_sqlsrv.so
可以通过
php -m | grep sqlsrv
验证是否成功