当试图在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
],
答案 0 :(得分:0)
说明:
PDO::SQLSRV_ENCODING_SYSTEM
是PDO_SQLSRV Driver Constant
,而不是选项名称。您应该在选项中使用PDO::SQLSRV_ATTR_ENCODING => PDO::SQLSRV_ENCODING_SYSTEM
。请记住,此选项是Microsoft SQL Server专用的SQL Server驱动程序专用驱动程序属性(PDO::SQLSRV_ATTR_ENCODING
和PDO::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)。