Laravel 到 SQL Server (sqlsrv).[PDOException] 找不到驱动程序
问题描述
介绍.我的 Laravel 应用程序使用的是 mysql,现在它需要托管在我工作的公司的网络中(我是一名远程工作者).而这家公司是微软的窥视者,所以我需要将 Laravel 集成到他们的 SQL Server 中.
Intro. My laravel app was using mysql, now it needs to be hosted in the network of the company I am working ( I am a remote-worker). And this company are Microsoft peeps, so I need to integrate the laravel to their SQL Server.
我的 .env 中有这个
I have this in my .env
DB_CONNECTION=sqlsrv
DB_HOST=ip.address.of.server
DB_PORT=3306
DB_DATABASE=my_db
DB_USERNAME=my_username
DB_PASSWORD=my_password
使用php artisan migrate
错误:
  [PDOException]
  could not find driver
我正在使用 Ubuntu,这是一个专为我设计的远程盒子(来自我的雇主).我之前曾尝试在我的 Laravel 应用程序中使用 sql server(使用我的 Windows PC).据我所知,我在 xampp php.ini 中编辑了一些文本.作为 Linux 新手,这对我来说太难了(因为我只使用 CLI).
I am using Ubuntu, a remote box dedicated for me (from my employer). I have tried using sql server in my laravel app before (using my Windows PC). As far as I remember, I edited some texts in the xampp php.ini. As a newbie Linux user, it is too hard for me (since i was using only CLI).
已编辑(新版本)
所以我已经获得了从 Ubuntu 到数据库服务器的连接.我使用了 sqlcmd -S 
So I already got the connectivity from Ubuntu to the Database server. I used the the sqlcmd -S <host> -U <username>
并且我测试了查询(例如 SELECT * from users_data)并且它有效.
and I tested the queries (such as SELECT * from users_data) and it works.
现在,我修改了 config/database.php 并添加了它.
Now, I modified the config/database.php and I added this. 
'sqlsrv' => [
                'driver'   => 'MSSQL',
                'host'     => env('DB_HOST', 'host.of.the.database'),
                'database' => env('DB_DATABASE', 'my_database'),
                'username' => env('DB_USERNAME', 'my_username'),
                'password' => env('DB_PASSWORD', 'my_pass'),
          'port'     => '1433',
                'prefix'   => '',
            ],
但是我遇到了一个错误:
but I got an Error:
[InvalidArgumentException]
  Unsupported driver [MSSQL]
MSSQL"是我用来配置 FreeTDS 的名称.
"MSSQL" is the name I use to configure the FreeTDS.
推荐答案
致后来者
确定你使用的 PHP 版本(我家目前使用的是 php 7.1,所以我安装了 php7.1-sybase)
Make sure of the PHP version you use (for me homestead currently using php 7.1, so I installed php7.1-sybase)
sudo apt-get install freetds-common freetds-bin unixodbc php7.1-sybase
司机是
'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'port' => env('DB_PORT', '1433'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
        ]
您可以使用tsql确保连接信息正确
You can make sure that the connection information is correct using tsql
TDSVER=8.0 tsql -H Host -U Username -D DatabaseName -p 1433 -P Password
                        这篇关于Laravel 到 SQL Server (sqlsrv).[PDOException] 找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
