Lim Socheat
Lim Socheat

Reputation: 715

Laravel migration cannot find driver when using sqlsrv database in windows

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

Upvotes: 4

Views: 23947

Answers (4)

endo64
endo64

Reputation: 2307

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.

Upvotes: 0

Kamlesh
Kamlesh

Reputation: 6135

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

enter image description here

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

Upvotes: 8

Tarek
Tarek

Reputation: 725

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

Upvotes: 1

Eazy Sam
Eazy Sam

Reputation: 308

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

Upvotes: 2

Related Questions