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

☆樱花仙子☆ 提交于 2020-01-11 10:16:19

问题


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.


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/44352961/laravel-connection-mssql-server-works-with-cli-but-not-in-browser

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!