'Connecting Laravel with SQL Server database always shows error "could not find driver"

I want to connect Laravel (version 8), with a SQL Server database (SQL Server 2008 R2).

I've done the installation and followed some tutorials with steps like the following, where the version I installed adapts to SQL Server 2008 R2, like this guide :

  1. Installed Microsoft® ODBC Driver 17 for SQL Server (I chose version 17 because of this)

  2. Installed PHP Driver version 5.6 by taking 2 files, namely php_pdo_sqlsrv_73_ts.dll and php_sqlsrv_73_ts.dll which I got from here (I chose version 5.6 based on this)

  3. I put the above 2 files in C:\larragon\bin\php\php-7.3.9-Win32-VC15-x64\ext

  4. I enabled the extension in php.ini, like this: extension=pdo_sqlsrv_73_ts, extension=sqlsrv_73_ts. It succeed, When I checked in php.info, it says pdo_sqlsrv

  5. Then I configured the database connection on Laravel's .env like this (I've created a database with that name):

DB_CONNECTION=sqlsrv
DB_HOST=192.168.101.103:86
DB_PORT=1433
DB_DATABASE=testlaravel
DB_USERNAME=faisallocal
DB_PASSWORD=faisallocal
  1. Then I run php artisan migrate on terminal.

But I always get an error like this:

[Illuminate\Database\QueryException

could not find driver (SQL: select * from sys.sysobjects where id = object_id(migrations) and xtype in ('U', 'V'))

at C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connection.php:712 708▕ // If an exception occurs when trying to run a query, we'll format the error 709▕ // message to include the bindings with SQL, which will make this exception a 710▕ // lot more helpful to the developer instead of just the database's errors. 711▕ catch (Exception $e) { 712▕ throw new QueryException( 713▕ $query, $this->prepareBindings($bindings), $e 714▕ ); 715▕ } 716▕ }

1 C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 PDOException::("could not find driver")

2 C:\larragon\www\redeempointappapi\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 PDO::__construct("dblib:host=192.168.101.103:86:1433;dbname=testlaravel;charset=utf8", "faisallocal", "faisallocal", [])]

What did I miss? I did this test locally, and I have XAMPP as well as Laragon with different versions, but wouldn't it be okay if I had a different port?

Please help anyone who has experience and has advice on this, I've been stuck at this point for weeks..

Thank you



Solution 1:[1]

php_pdo_sqlsrv_73_ts.dll It depends of your version of php

for example: php_pdo_sqlsrv_73_ts.dll is for php 7.3

in the next link you can see this information.

https://docs.microsoft.com/en-us/sql/connect/php/system-requirements-for-the-php-sql-driver?view=sql-server-ver15

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Erick Mejias Alvarez