【问题标题】:PDOException: Can't open lib 'ODBC Driver 13 for SQL Server'PDOException: 无法打开 lib 'ODBC Driver 13 for SQL Server'
【发布时间】:2018-01-10 11:22:43
【问题描述】:

我尝试从 macOS 连接 MSSQL。我的 PHP/Laravel 应用程序在 macOS 中运行。

基于这个link,我运行了以下两个命令:

# sudo pecl install sqlsrv
# sudo pecl install pdo_sqlsrv

我收到消息说它已经安装了。

pecl/pdo_sqlsrv is already installed and is the same as the released version 4.3.0
install failed.

但是当我尝试连接 mssql 时,

#php artisan migrate:install

我得到以下异常:

Illuminate\Database\QueryException]                                                                                                   
  SQLSTATE[01000]: [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found (SQL: create table "migrat  
  ions" ("id" int identity primary key not null, "migration" nvarchar(191) not null, "batch" int not null))                              



  [PDOException]                                                                                              
  SQLSTATE[01000]: [unixODBC][Driver Manager]Can't open lib 'ODBC Driver 13 for SQL Server' : file not found 

我还需要安装什么?我的php版本是7.1


我尝试时遇到的问题

# brew install msodbcsql 
Error: Formulae found in multiple taps: 
 * microsoft/msodbcsql/msodbcsql
 * microsoft/mssql-preview/msodbcsql

Please use the fully-qualified name e.g. `microsoft/msodbcsql/msodbcsql` to refer the formula.

所以改成:

# brew install  microsoft/msodbcsql/msodbcsql

然后我得到这个;

Do you accept the license terms? (Enter YES or NO)
YES
==> odbcinst -u -d -n "ODBC Driver 13 for SQL Server"
==> odbcinst -i -d -f ./odbcinst.ini
Last 15 lines from /Users/ratha/Library/Logs/Homebrew/msodbcsql/02.odbcinst.ini:
2017-08-03 14:03:06 +1000

odbcinst -i -d -f ./odbcinst.ini

odbcinst: SQLInstallDriverEx failed with Invalid install path.

If reporting this issue please do so to (not Homebrew/brew or Homebrew/core):
microsoft/msodbcsql

/usr/local/Homebrew/Library/Homebrew/utils/github.rb:226:in `raise_api_error': curl failed!  (GitHub::Error)
curl: (22) The requested URL returned error: 422 Unprocessable Entity
curl: (3) <url> malformed
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:184:in `open'
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:233:in `issues_matching'
    from /usr/local/Homebrew/Library/Homebrew/utils/github.rb:272:in `issues_for_formula'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:369:in `fetch_issues'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:365:in `issues'
    from /usr/local/Homebrew/Library/Homebrew/exceptions.rb:419:in `dump'
    from /usr/local/Homebrew/Library/Homebrew/brew.rb:133:in `rescue in <main>'
    from /usr/local/Homebrew/Library/Homebrew/brew.rb:26:in `<main>

【问题讨论】:

标签: php sql-server macos laravel


【解决方案1】:

我相信“Microsoft ODBC Driver 13”的先决条件尚未安装在 Mac 上。

根据blog 的帖子,微软似乎正在开发 Mac 版本的驱动程序。

由于您正在使用 Laravel;第一次尝试;

composer update && upgrade

从web应用的根目录看是否能自动拉取所有依赖。

如果不尝试按照上面提供的链接中的说明安装驱动程序。

如果您已经安装了 ODBC 驱动程序,它应该位于您 Mac 上的以下目录中;

/Library/ODBC/

干杯。

【讨论】:

  • 谢谢。我遵循了上面的博客文章,但在这一行遇到了问题;酿造安装 msodbcsql 。我已经用我面临的问题编辑了我的问题
  • 您可能需要ODBC Manager for Mac。它曾经随 OSX 一起提供,但较新的 OS 没有它。安装然后重试?
  • 我做到了。但又是同样的问题:(
  • @Genjutsu 的回答应该能带你走完剩下的路。祝你好运。
【解决方案2】:

您需要使用--no-sandbox 作为brew install --no-sandbox msodbcsql 安装ODBC

https://github.com/Microsoft/homebrew-mssql-release/issues/1

【讨论】:

  • brew install --no-sandbox msodbcsql 解决了我遇到的实际问题
  • 这也解决了我遇到的问题
【解决方案3】:

重新安装软件包:

brew tap microsoft/msodbcsql https://github.com/Microsoft/homebrew-mssql-release
ACCEPT_EULA=y brew reinstall --no-sandbox msodbcsql mssql-tools

如果仍然发生,请运行:

cp -v "$(brew list msodbcsql | grep odbcinst.ini$)" ~/.odbcinst.ini

复制定义 SQL ODBC 驱动程序位置的 INI 文件。

手动创建文件,例如

printf "[ODBC Driver 13 for SQL Server]\nDescription=Microsoft ODBC Driver 13 for SQL Server\nDriver=/usr/local/lib/libmsodbcsql.13.dylib\n" >> ~/.odbcinst.ini

错误报告:SQL Server : Can't open lib 'ODBC Driver 13 for SQL Server'.

请参阅:Installing the Microsoft ODBC Driver for SQL Server on Linux and macOS

如果您使用 Anaconda,请查看此问题:ODBC Driver 13 for SQL Server can't open lib

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-15
    • 2020-04-20
    • 1970-01-01
    • 2023-01-26
    • 1970-01-01
    • 1970-01-01
    • 2018-08-14
    • 1970-01-01
    相关资源
    最近更新 更多