Laravel migration cannot find driver when using sqlsrv database in windows

十年热恋 提交于 2021-02-19 03:55:09

问题


I am using sqlsrv database connection in my project as I need to connect to Microsoft SQL Database.

I have successfully installed the sqlsrv driver because I can connect to the Database to retrieve data.

But when I try to do the Laravel Migration, it shows an error:

Illuminate\Database\QueryException  : could not find driver (SQL: select * from sysobjects where type = 'U' and name = migrations)

Below is my .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

回答1:


How to use SQL Server DLL files with PHP 7.2 version on xampp

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.

https://pecl.php.net/package/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.

extension=pdo_sqlsrv
extension=sqlsrv

Do not change actual filename which you put in /xampp/php/ext/ directory.

"7.2 Thread Safe (TS) x86" worked for me for 'sqlsrv' and 'pdo_sqlsrv' extensions.

Restart xampp or apache then you can see enabled 'pdo_sqlsrv' extension when you print phpinfo() in a test php file

It was very hard to find this solution. I hope, this will also help you. All the best :)




回答2:


You may need to upgrade your PHP version to PHP 7.1. Now make sure that the files config/database.php and .env are configured properly.

See this one: https://laracasts.com/discuss/channels/general-discussion/connect-laravel-to-microsoft-sql




回答3:


After fighting with it for a while found a solution :

you need to downloaded it from here then extract the files in your php folder




回答4:


For PHP 7.4 on Windows 10 (x64), I've solved same error s below:

  1. Downloaded the driver from https://www.microsoft.com/en-us/download/details.aspx?id=20098
  2. Extracted the archive and copied the file php_pdo_sqlsrv_74_ts_x64.dll to the ext folder (C:\Program Files\php74\ext in my setup)
  3. Added extension=php_pdo_sqlsrv_74_ts_x64.dll into php.ini file

In my .env file I've DB_CONNECTION=sqlsrv so I first thought php_sqlsrv_74_ts_x64.dll should be used but it didn't work.



来源:https://stackoverflow.com/questions/49333044/laravel-migration-cannot-find-driver-when-using-sqlsrv-database-in-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!