Laravel migration cannot find driver when using sqlsrv database in windows

Lim Socheat picture Lim Socheat · Mar 17, 2018 · Viewed 10.9k times · Source

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

Answer

Kamlesh picture Kamlesh · Aug 19, 2019

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 :)