未定义的类常量'SQLSRV_ENCODING_SYSTEM'

时间:2018-11-26 11:24:49

标签: sql-server laravel laravel-5 sqlsrv

当试图在laravel上运行php artisan迁移时,我遇到了错误

In database.php line 79:
Undefined class constant 'SQLSRV_ENCODING_SYSTEM'

我已经安装了sql驱动程序等,但不确定如何解决此问题

database.php文件

'sqlsrv' => [
        'driver' => 'sqlsrv',
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', '1433'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'charset' => 'utf8',
        'prefix' => '',
        'options' => [PDO::SQLSRV_ENCODING_SYSTEM => false], // Used for MSSQL encoding
    ],

1 个答案:

答案 0 :(得分:0)

说明:

PDO::SQLSRV_ENCODING_SYSTEMPDO_SQLSRV Driver Constant,而不是选项名称。您应该在选项中使用PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_SYSTEM。请记住,此选项是Microsoft SQL Server专用的SQL Server驱动程序专用驱动程序属性(PDO::SQLSRV_ATTR_ENCODINGPDO::SQLSRV_ATTR_DIRECT_QUERY中的一个)。

<?php

...
'sqlsrv' => [
    'driver' => 'sqlsrv',
    'host' => env('DB_HOST', 'localhost'),
    'port' => env('DB_PORT', '1433'),
    'database' => env('DB_DATABASE', 'forge'),
    'username' => env('DB_USERNAME', 'forge'),
    'password' => env('DB_PASSWORD', ''),
    'charset' => 'utf8',
    'prefix' => '',
    'options' => [PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_SYSTEM]
],

...
?>

注释:

文档:Microsoft SQL Server Functions (PDO_SQLSRV)Constants (Microsoft Drivers for PHP for SQL Server)