环境
- mac: macOs Monterey 12.3.1 (intel芯片)
- php: php7.3
问题描述
$data = mssql()->query($sql);
连接 mssql 报错如下
Hyperf\Pool\Exception\ConnectionException:
Connection reconnect failed.:SQLSTATE[IMSSP]:This extension requires the Microsoft ODBC Driver for SQL Server to communicate with SQL Server. Access the following URL to download the ODBC Driver for SQL Server for x64: https://go.microsoft.com/fwlink/?LinkId=163712 in file /Users/zhangqiang/xczxw/xczxw_api_php/app/Library/Mssql/PDOConnection.php on line 86
解决方法
-
安装php扩展(
php7.3 只能支持到 5.9,5.10要求最低7.4)sudo pecl install sqlsrv-5.9.0
sudo pecl install pdo_sqlsrv-5.9.0 -
安装
SQL Server ODBC 17(测试18不支持)安装地址: https://docs.microsoft.com/en-us/sql/connect/odbc/linux-mac/install-microsoft-odbc-driver-sql-server-macos?view=sql-server-ver15
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" brew tap microsoft/mssql-release https://github.com/Microsoft/homebrew-mssql-release brew update HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y brew install msodbcsql17 mssql-tools
在MacOs Monterey 12.3.1上使用PHP7.3连接MSSQL时遇到错误,提示需要Microsoft ODBC Driver for SQL Server。解决方法包括安装php扩展sqlsrv和pdo_sqlsrv的5.9.0版本,以及安装SQLServer ODBC17。安装过程涉及使用pecl命令和Homebrew。
5219

被折叠的 条评论
为什么被折叠?



