Laravel:PDO异常,即使已安装并测试了驱动程序,也找不到驱动程序 [英] Laravel: PDO Exception, cannot find driver even though the driver is installed and tested

查看:229
本文介绍了Laravel:PDO异常,即使已安装并测试了驱动程序,也找不到驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究必须连接到现有MS SQL Server数据库的Laravel 5.1项目.我的项目当前在使用Apache 2.4.18的Ubuntu 16.04 LTS服务器上.我已经在计算机上安装了用于SQL Server(版本13.0.0.0)的Microsoft ODBC Linux驱动程序,并使用sqlcmd命令对其进行了手动测试:

I'm working on a Laravel 5.1 project that has to connect to an existing MS SQL Server database. My project is currently on a Ubuntu 16.04 LTS server using Apache 2.4.18. I've installed the Microsoft ODBC Linux driver for SQL Server (version 13.0.0.0) on the machine and tested it manually with the sqlcmd command:

sqlcmd -S DatabaseIPAddress -U DatabaseUsername

一切正常.我可以登录数据库没问题.但是,当我使用php artisan迁移数据库时,它不起作用.我收到错误消息:

It all worked fine. I can log on to the database no problem. When I go to migrate my database with php artisan however, it doesn't work. I get the error:

  [PDOException]
  could not find driver

我已经将它作为database.php中的设置:

I've got this as the setup in database.php:

'sqlsrv' => [
            'driver'   => 'sqlsrv',
            'host'     => env('DB_HOST', 'localhost'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset'  => 'utf8',
            'prefix'   => '',
],

数据库登录信息保存在.env文件中,并且SQL Server设置为默认值:

The database login information is saved in the .env file and SQL Server is set as the default:

'default' => env('DB_CONNECTION', 'sqlsrv'),

有关可能发生的情况的任何帮助吗?我已经在互联网上阅读了一堆帖子(此处).人们对于不同类型的数据库也遇到过类似的问题.他们必须更改其php.ini文件的配置,并添加一些有关扩展的代码行.也许沿着这些思路?我在php.ini文件中尝试了一些我认为可能可行的方法,例如:

Any help as to what could be going on? I've read a bunch of posts on the internet (here and here). People have had similar issues with different types of databases. They had to change the configuration of their php.ini file adding some lines about extensions. Maybe something along those lines? I've tried some various things in the php.ini file that I thought might work, such as:

; This is the extension for the Microsoft SQLSRV ODBC Driver.
; The driver seems to be located at this file path.
extionsion=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0

重新引导,测试,但无济于事.我一直在这上面砸头一阵子.任何帮助将不胜感激.谢谢.

rebooted, tested, but to no avail. I've been bashing my head against the wall for a while on this one. Any help would be greatly appreciated. Thanks.

推荐答案

按照以下步骤操作
sudo apt-get install php5-mssql
更新/etc/freetds/freetds.conf

Follow these steps
sudo apt-get install php5-mssql
Update /etc/freetds/freetds.conf

[global]  
# TDS protocol version
; tds version = 4.2
tds version = 8.0
client charset = UTF-8`

将此行添加到 php.ini

mssql.charset = "UTF-8"

参考资料: Laracast讨论

这篇关于Laravel:PDO异常,即使已安装并测试了驱动程序,也找不到驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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