简体   繁体   中英

Laravel connection MSSqL server works with cli, but not in browser

After installing the dll's to use with MSSqL server, the command php artisan migrate ran correctly and the tables were made in the db . So I thought the connection would work for this application.

I then used the command php artisan make:auth (which doesn't use the db connection) to scaffold the authentication files.

Now when I try to register anyone I get errors:

PDOExeption (1/2)

Could not find driver

and

PDOExeption (2/2)

Could not find driver (select count(*) from .....

Now I tried to see if using the cli commands still work and both php artisan migrate:rollback and php artisan migrate still work.

Environment: Windows 7 with xampp installed. Versions: Laravel 5.4, php 7.1

Not that it matters but here are parts of my .env and database.php files:

`database.php`
        'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', '10.0.0.40'),
        'port' => env('DB_PORT', '1433'),
        'database' => env('DB_DATABASE', 'sqlcon'),
        'username' => env('DB_USERNAME', 'sa'),
        'password' => env('DB_PASSWORD', 'test'),
        'charset' => 'utf8',
        'prefix' => '',
    ],

`.env`
DB_CONNECTION=sqlsrv
DB_HOST=10.0.0.40
DB_PORT=1433
DB_DATABASE=sqlcon
DB_USERNAME=sa
DB_PASSWORD=test

So how come the cli commands work and the browser don't?

Doesn't laravel use the same config for both cli and browser connections?


Update: added some extra info

C:\\xampp\\htdocs\\sqlcon>php --ini

Configuration File (php.ini) Path: C:\\Windows

Loaded Configuration File: C:\\xampp\\php\\php.ini

Scan for additional .ini files in: (none)

Additional .ini files parsed: (none)

Used this to show my php configuration and it shows:

Loaded Configuration File C:\\xampp\\php\\php.ini

The php -m command shows:

C:\\xampp\\htdocs\\sqlcon>php -m

[PHP Modules]

bcmath

...(some others)

pdo_mysql

pdo_sqlite

pdo_sqlsrv (this one is enabled)

Phar

...

[Zend Modules]

According to php -m the pdo_sqlsrv is enabled, but I can't find any reference to it in the phpinfo page.

I had the same issue and I have solved as follow (WAMP):


1. Download Microsoft Drivers for PHP for SQL Server

You should download following 2 .dll files.

  • PHP PDO SQL Server Driver
    ex.:- php_pdo_sqlsrv_7_ts_x64.dll
  • PHP SQL Server Driver
    ex.:- php_sqlsrv_7_ts_x64.dll

You have to concern about:

  • Operating System.
  • Operating System version (32bit/64bit).
  • PHP version.
  • PHP Thread Safety (ts/nts).

(My Case: Windows 7 64bit / PHP 7 / Thread Safe -> _7_ts_x64)


2. Install Microsoft Drivers for PHP for SQL Server in WAMP

Put those downloaded 2 .dll files into wamp64\\bin\\php\\php*\\ext


3. Configure Microsoft Drivers for PHP for SQL Server in WAMP

Type following code after default extensions:

extension=php_pdo_sqlsrv_7_ts_x64.dll
extension=php_sqlsrv_7_ts_x64.dll

in following files:
wamp64\\bin\\apache\\apache*\\bin\\php.ini
wamp64\\bin\\php\\php*\\php.ini
wamp64\\bin\\php\\php*\\phpForApache.ini


4. Restart WAMP

What I thought had fixed the problem

When installing the driver in php.ini I used the following line as this was the name of the file in the extension directory ( extension_dir="C:\\xampp\\php\\ext" ):

extension=php_pdo_sqlsrv_71_ts.dll

Changing both the name of the file in this directory and the reference to it in the php.ini file and restarting apache solved the problem.

So now the file is php_pdo_sqlsrv.dll and the reference is:

extension=php_pdo_sqlsrv.dll

What actually fixed the problem

Installing this after downloading the dlls and making the change to php.ini .

Don't forget to restart apache .

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