2017-08-03 123 views
2

我嘗試從macOS連接MSSQL。我的PHP/Laravel應用程序在macOS中運行。PDOException:無法爲SQL Server打開lib'ODBC驅動程序13'

在此基礎上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> 
+0

報告問題在Microsoft GIt https://github.com/Microsoft/msphpsql/issues/489 – Ratha

回答

1

我相信在Mac上還沒有安裝「Microsoft ODBC Driver 13」的先決條件。

根據這篇blog的帖子,微軟似乎正在開發Mac版本的驅動程序。

由於您正在與Laravel合作;第一次嘗試;

composer update && upgrade 

從Web應用程序的根目錄下,看它是否能自動把所有的依賴關係。

如果不按照上面提供的鏈接指示安裝驅動程序。

如果您已經安裝了ODBC驅動程序,它應該位於Mac上的以下目錄中;

/Library/ODBC/ 

乾杯。

+0

謝謝。我在博客文章以上,我在這一行得到問題; brew安裝msodbcsql。我編輯了我的問題,並且遇到了我所面臨的問題 – Ratha

+1

您可能需要[ODBC Manager for Mac](http://www.odbcmanager.net/)。它曾經隨OSX一起發佈,但較新的操作系統沒有它。安裝,然後再試一次? – Manu

+0

我做到了。但同樣的問題再次:( – Ratha

1

重新安裝包安裝ODBC:

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 

複製INI文件定義了th SQL ODBC驅動程序的位置。

手動創建文件,例如,

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

相關問題