Laravel 到 SQL Server (sqlsrv).[PDOException] 找不到驱动程序

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

问题描述

限时送ChatGPT账号..

介绍.我的 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 -U <用户名>

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

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)