如何在 Laravel Homestead 中连接 MSSQL?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36424375/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 13:32:16  来源:igfitidea点击:

How to connect MSSQL in Laravel homestead?

sql-serverlaravelhomestead

提问by AmitChaudhary

I am trying to connect with a MSSQL database using laravel homestead. It always throws the exception:

我正在尝试使用 laravel homestead 连接 MSSQL 数据库。它总是抛出异常:

PDOException in Connector.php line 55: could not find driver.

Connector.php 第 55 行中的 PDOException:找不到驱动程序。

I've seen a lot of people talking about FreeTDS and Sybase drivers, but I can't seem to figure out what I need to enable laravel/php access to MSSQL databases from a Linux Web Server running the Laravel Homestead Vagrant box.

我看到很多人谈论 FreeTDS 和 Sybase 驱动程序,但我似乎无法弄清楚我需要什么才能从运行 Laravel Homestead Vagrant 框的 Linux Web 服务器启用 laravel/php 访问 MSSQL 数据库。

回答by AmitChaudhary

I did lots of R&D for resolving this issue. Finally found the solution:

我做了很多研发来解决这个问题。终于找到了解决办法:

Laravel vagrant is using php 7. For mssql support we have to enable the relevant sybase driver for linux :

Laravel vagrant 使用的是 php 7。对于 mssql 支持,我们必须为 linux 启用相关的 sybase 驱动程序:

To Enable MSSQL Support for PHP 7:

为 PHP 7 启用 MSSQL 支持:

First, ssh into your box vagrant ssh from the Homestead folder.

首先,从 Homestead 文件夹 ssh 进入你的盒子 vagrant ssh。

Command : vagrant ssh

命令 : vagrant ssh

Install the Sybase package for enabling the support for PDO and Mssql.

安装 Sybase 软件包以启用对 PDO 和 Mssql 的支持。

Command : sudo apt-get install php7.0-sybase

命令 : sudo apt-get install php7.0-sybase

then run php -mon the ssh to make sure pdo_dblibis enabled.

然后php -m在 ssh 上运行以确保启用了pdo_dblib

All Done!!!! Cheers

全部完成!!!!干杯

回答by ankittiwaari

Laravel uses PDO extension to connect to database, you could check if the extension is enabled using

Laravel 使用 PDO 扩展连接到数据库,你可以检查扩展是否启用使用

var_dump(class_exists('PDO'))

Also, if you could post the specific error, it would be great.

另外,如果您可以发布特定的错误,那就太好了。

回答by Levy

Thanks for this. Still works as of now with:

谢谢你。至今仍适用于:

  1. php7.2-sybase

  2. using DB_HOST= IP_ADDRESS\NAMED_INSTANCE

  3. Commenting out the PORT directive in both .env and database.php

  1. php7.2-sybase

  2. 使用 DB_HOST= IP_ADDRESS\NAMED_INSTANCE

  3. 在 .env 和 database.php 中注释掉 PORT 指令