2

I am using php 8.1.3 for this project. My file .env connection:

DB_CONNECTION=sqlsrv
DB_HOST=
DB_PORT=1433
DB_DATABASE=db_PendaftaranOnline
DB_USERNAME=
DB_PASSWORD=

I get this error:

PDOException: could not find driver in C:\laragon\www\project\registrasi-online-master\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:70 Stack trace: #0 C:\laragon\www\project\registrasi-online-master\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php(70): PDO->__construct('dblib:host=192....', 'client', 'dbop', Array)

enter image description here

How to fix this?

  • You need to enable `pdo_mysql` in `php.ini` – aceraven777 Mar 25 '22 at 02:24
  • I am using laragon, and already done with this : extension=pdo_mysql – Dear Janice Mar 25 '22 at 02:27
  • @aceraven777 what has `MySQL` to do with `SQLSrv = Microsoft SQL`? @DearJanice You are missing the SQLServer driver... you never installed it and it is a pain in where the sun does not shine... – matiaslauriti Mar 25 '22 at 02:32
  • sorry, didn't noticed that the `DB_CONNECTION` is `sqlsrv`. well @matiaslauriti is right. I'm not familiar with laragon. you have to find a way to enable `sqlsrv` on laragon. – aceraven777 Mar 25 '22 at 02:38
  • But it's works yesterday, and for today I get that error. Can you give me reference to instal SQLServer driver @matiaslauriti ? – Dear Janice Mar 25 '22 at 02:42
  • @DearJanice plz show contents of `config/database.php` (hide private fields) so we can see what driver you are setting – Thanh Dao Mar 25 '22 at 02:46
  • 'connections' => [ 'sqlsrv' => [ 'driver' => 'sqlsrv', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '1433'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'prefix' => '', 'prefix_indexes' => true, ], ], This one? – Dear Janice Mar 25 '22 at 02:49
  • @ThanhDao please kinda check it > – Dear Janice Mar 25 '22 at 03:16
  • @DearJanice The driver you was set is `sqlsrv` (SQL server). There a lots of issues you may to check, at least I know only PHP ext installed/enabled (As I never worked PHP with SQLSV). This article may help you more https://stackoverflow.com/questions/39860273/laravel-to-sql-server-sqlsrv-pdoexception-could-not-find-driver. Take a look at Laravel documentation and ensure your configuration fully activated https://laravel.com/docs/8.x/database#mssql-configuration – Thanh Dao Mar 25 '22 at 03:24
  • @DearJanice https://learn.microsoft.com/en-us/iis/application-frameworks/install-and-configure-php-on-iis/install-the-sql-server-driver-for-php, check the related links inside that blogpost – matiaslauriti Mar 25 '22 at 13:25

0 Answers0