laravel 在windows下使用sqlsrv数据库Laravel迁移找不到驱动
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49333044/
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
Laravel migration cannot find driver when using sqlsrv database in windows
提问by Lim Socheat
I am using sqlsrv databaseconnection in my project as I need to connect to Microsoft SQL Database.
我在我的项目中使用sqlsrv 数据库连接,因为我需要连接到 Microsoft SQL 数据库。
I have successfully installed the sqlsrv driverbecause I can connect to the Database to retrieve data.
我已经成功安装了sqlsrv 驱动程序,因为我可以连接到数据库来检索数据。
But when I try to do the Laravel Migration, it shows an error:
但是当我尝试进行 Laravel 迁移时,它显示了一个错误:
Illuminate\Database\QueryException : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)
Below is my .env
下面是我的 .env
DB_CONNECTION=sqlsrv
DB_HOST=**********.database.windows.net
DB_PORT=1433
DB_DATABASE=****************_4cd1_9d18_2a7d9ddbcd13
DB_USERNAME=***************_4cd1_9d18_2a7d9ddbcd13_ExternalWriter
DB_PASSWORD=***************
php.ini
配置文件
extension=php_xmlrpc.dll
extension=php_xsl.dll
extension=php_pdo_sqlsrv_7_nts_x64.dll
extension=php_pdo_sqlsrv_7_nts_x86.dll
extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_pdo_sqlsrv_7_ts_x86.dll
extension=php_pdo_sqlsrv_71_nts_x64.dll
extension=php_pdo_sqlsrv_71_nts_x86.dll
extension=php_pdo_sqlsrv_71_ts_x64.dll
extension=php_pdo_sqlsrv_71_ts_x86.dll
extension=php_sqlsrv_7_nts_x64.dll
extension=php_sqlsrv_7_nts_x86.dll
extension=php_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x86.dll
extension=php_sqlsrv_71_nts_x64.dll
extension=php_sqlsrv_71_nts_x86.dll
extension=php_sqlsrv_71_ts_x64.dll
extension=php_sqlsrv_71_ts_x86.dll
回答by Kamlesh
How to use SQL Server DLL files with PHP 7.2 version on xampp
如何在 xampp 上使用带有 PHP 7.2 版本的 SQL Server DLL 文件
https://github.com/Microsoft/msphpsql/releases
https://github.com/Microsoft/msphpsql/releases
To download Windows DLLs for PHP 7.1 or above from the PECL repository, please go to the SQLSRV or PDO_SQLSRV PECL page.
要从 PECL 存储库下载 PHP 7.1 或更高版本的 Windows DLL,请访问 SQLSRV 或 PDO_SQLSRV PECL 页面。
https://pecl.php.net/package/sqlsrv/5.6.1/windows
https://pecl.php.net/package/sqlsrv/5.6.1/windows
https://pecl.php.net/package/pdo_sqlsrv/5.6.1/windows
https://pecl.php.net/package/pdo_sqlsrv/5.6.1/windows
NOTE: Do not forget to remove 'php_' prefix when you add extension dll filename in php.ini file. eg.
注意:在 php.ini 文件中添加扩展 dll 文件名时,不要忘记删除 'php_' 前缀。例如。
extension=pdo_sqlsrv
extension=sqlsrv
Do not change actual filename which you put in /xampp/php/ext/ directory.
不要更改您放在 /xampp/php/ext/ 目录中的实际文件名。
"7.2 Thread Safe (TS) x86" worked for me for 'sqlsrv' and 'pdo_sqlsrv' extensions.
“7.2 线程安全 (TS) x86”适用于我的 'sqlsrv' 和 'pdo_sqlsrv' 扩展。
Restart xampp or apache then you can see enabled 'pdo_sqlsrv' extension when you print phpinfo() in a test php file
重新启动 xampp 或 apache,然后您可以在测试 php 文件中打印 phpinfo() 时看到启用的“pdo_sqlsrv”扩展
It was very hard to find this solution. I hope, this will also help you. All the best :)
很难找到这个解决方案。我希望,这也能帮助你。祝一切顺利 :)
回答by Eazy Sam
You may need to upgrade your PHP version to PHP 7.1.Now make sure that the files config/database.phpand .envare configured properly.
您可能需要将 PHP 版本升级到 PHP 7.1。现在确保文件config/database.php和.env配置正确。
See this one: https://laracasts.com/discuss/channels/general-discussion/connect-laravel-to-microsoft-sql
看到这个:https: //laracasts.com/discuss/channels/general-discussion/connect-laravel-to-microsoft-sql