Laravel连接MSSqL服务器可用于cli,但不能在浏览器中使用 [英] Laravel connection MSSqL server works with cli, but not in browser

查看:69
本文介绍了Laravel连接MSSqL服务器可用于cli,但不能在浏览器中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

安装dll's以与MSSqL服务器一起使用后,命令php artisan migrate正确运行,并且在db中创建了表.因此,我认为该连接将对此应用程序有效.

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.

然后我使用命令php artisan make:auth(不使用db连接)来构架认证文件.

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:

PDO肽段(1/2)

找不到驱动程序

PDOExeption(2/2)

找不到驱动程序(从......

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

现在,我尝试查看使用cli命令是否仍然有效,并且php artisan migrate:rollbackphp artisan migrate仍然有效.

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

环境: 安装了xampp的Windows 7. 版本:Laravel 5.4,php 7.1

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

没关系,但这是我的.envdatabase.php文件的一部分:

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

那么cli命令如何起作用而浏览器却不起作用?

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

laravel是否不对cli和浏览器连接使用相同的配置?

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

更新:添加了一些额外的信息

Update: added some extra info

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

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

配置文件(php.ini)路径:C:\ Windows

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

已加载的配置文件:C:\ xampp \ php \ php.ini

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

扫描以下位置的其他.ini文件:(无)

Scan for additional .ini files in: (none)

已解析的其他.ini文件:(无)

Additional .ini files parsed: (none)

使用显示我的php配置,它显示:

Used this to show my php configuration and it shows:

已加载的配置文件C:\ xampp \ php \ php.ini

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

php -m命令显示:

The php -m command shows:

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

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

[PHP模块]

bcmath

...(另一些)

pdo_mysql

pdo_mysql

pdo_sqlite

pdo_sqlite

pdo_sqlsrv(已启用此功能)

pdo_sqlsrv (this one is enabled)

Phar

...

[Zend模块]

根据php -m,已启用pdo_sqlsrv,但在phpinfo页中找不到对此的任何引用.

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

推荐答案

我认为已解决问题的东西

php.ini中安装驱动程序时,我使用了以下行,因为这是扩展目录(extension_dir="C:\xampp\php\ext")中文件的名称:

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

更改此目录中文件的名称以及php.ini文件中对该文件的引用,然后重新启动apache,即可解决此问题.

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.

所以现在文件是php_pdo_sqlsrv.dll,引用是:

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

extension=php_pdo_sqlsrv.dll

实际上是什么解决了问题

在下载此 >并更改为php.ini.

What actually fixed the problem

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

别忘了重新启动apache.

这篇关于Laravel连接MSSqL服务器可用于cli,但不能在浏览器中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆