phpsql-serverlaravellaragon

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

  • So this all happened because of the detected different versions of PHP and SQL Server drivers.

    For information, I have 3 local servers, namely:

    1. XAMPP 1.7.3,
    2. XAMPP 3.?.? (I forgot the version details),
    3. and Laragon.

    The problem that occurs is, when I want to develop apps using the Laragon server AND I use the local Terminal/Command Prompt (Shortcut: Windows + CMD), the PHP versions from other local servers will collide with each other.

    When I run a Laravel command, check the PHP version, or whatever, the local Command Prompt directs me to the version of XAMPP above that I have installed, so any .dll or plugins you install in Laragon won't be detected!

    Finally I was able to finish my installation and do a lot of CMD commands according to the version I want, is how to use the built-in CMD/Terminal from Laragon (Click on Terminal under Laragon application)

    From this Terminal, all the .dll plugins that you install, and all the cmd commands that you enter, will match the Laragon version you are using, they won't be strayed to another local server! :D