简体   繁体   中英

PDOException::(“could not find driver”) Laravel & sql server

I'm trying to connect Laravel with a multiple sqlserver databases, I defined the connections on my database.php file correctly :

'connections' => [



    'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '16000'),
        'database' => env('DB_DATABASE', 'dbname'),
        'username' => env('DB_USERNAME', 'me'),
        'password' => env('DB_PASSWORD', 'me'),
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
    ],
    'sqlsrv2' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '16000'),
        'database' => env('DB_DATABASE_2', 'dbname2'),
        'username' => env('DB_USERNAME', 'me'),
        'password' => env('DB_PASSWORD', 'me'),
        'charset' => 'utf8',
        'prefix' => '',
        'prefix_indexes' => true,
    ],

],

and set my .env file

DB_CONNECTION=sqlsrv
DB_HOST=127.0.0.1
DB_PORT=16000
DB_DATABASE=dbname
DB_USERNAME=me
DB_PASSWORD=me

I try to verify the connectivity to my sql server database from another application and it's working perfectly. then I created a model on my laravel application and once I type php artisan migrate I get this error : 在此输入图像描述

anyone can help to resolve this problem ?

UPDATE !

After adding pdo sqlsrv extensions to my ext folder and my php.ini i get this error : [![enter image description here][2]][2]

[![enter image description here][3]][3]

UPDATE 3 :

After installing odbc 13 i got this problem 在此输入图像描述

Ah, WAMPServer has 2 seperate php.ini files.

One is used by PHP under Apache and the other by the PHP CLI.

I see you are using the CLI, so you need to check that you have included the SQL Server drivers extension in the CLI php.ini file.

You will find that in:

C:\wamp64\bin\php\php{version}\php.ini

You have to edit this manually, there is no menu link to do this, the menu link to edit the php.ini only edits the PHP under Apache version of php.ini

Make sure you edit the php.ini file in the folder that matches the version of PHP you are actually using for this project, as of course you can have multiple versions of PHP installed under WAMPServer

UPDATE: Second Problem

You have added the 32bit AND 64 bit SQL Server drivers to your ext folder!

Your WAMPServer menu shows

1. php_sqlsrv_72_ts_x64 
2. php_sqlsrv_72_ts_x32
3. php_pdo_sqlsrv_72_ts_x64 
4. php__pdo_sqlsrv_72_ts_x32

as you are using 64 bit wamp, you should only have these 2

1. php_sqlsrv_72_ts_x64 
2. php_pdo_sqlsrv_72_ts_x64 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM