mac php7.3 odbc安装

柴丰
2023-12-01

环境

  • 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

解决方法

  1. 安装php扩展(php7.3 只能支持到 5.9,5.10要求最低7.4)

    sudo pecl install sqlsrv-5.9.0
    sudo pecl install pdo_sqlsrv-5.9.0

  2. 安装 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
    
 类似资料: