Laravel到SQL Server(sqlsrv). [PDOException]找不到驱动程序 [英] Laravel to SQL Server (sqlsrv). [PDOException] could not find driver

查看:126
本文介绍了Laravel到SQL Server(sqlsrv). [PDOException]找不到驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简介.我的laravel应用程序使用的是mysql,现在它需要托管在我正在工作的公司的网络中(我是远程工作人员).而且这家公司是Microsoft窥视者,因此我需要将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 <host> -U <username>

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'   => '',
            ],

但我收到一个错误:

[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]找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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