4

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
2
  • Possible duplicate of Laravel 5 PDOException Could Not Find Driver Commented Mar 17, 2018 at 6:10
  • @SagarGautam, thanks for your comment, I am using Windows OS and I also have the required PDO extension in my php.ini as you can see in the edited. Commented Mar 17, 2018 at 6:17

4 Answers 4

8

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

Sign up to request clarification or add additional context in comments.

Comments

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

2 Comments

My environment already running on PHP 7.1. PHP 7.1.9 (cli) (built: Aug 30 2017 18:34:46)
php_sqlsrv.dll You need to manually install this extension. Include extension=php_sqlsrv.dll in your php.ini and restart the server.
1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.