doucang9673 2016-07-15 19:59
浏览 76
已采纳

Laravel:PDO异常,即使安装并测试了驱动程序也无法找到驱动程序[重复]

This question already has an answer here:

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

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

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

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

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

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.

</div>
  • 写回答

1条回答 默认 最新

  • duankange2433 2016-07-16 16:10
    关注

    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`
    

    Add this line to php.ini

    mssql.charset = "UTF-8"
    

    Reference : Laracast discussion

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?