dongqiang1894 2018-10-10 07:27
浏览 531

如何将SQL Server与Yii2连接

I got errors when trying to connecting SQL server with yii2.

SQL Server and PHP code are in separated server.

The PHP environment is PHP 7.0.31 on Ubuntu 18.04.

And Database Server Environment is MS SQL SERVER v9.00.1399.06 on Window NT 6.1

And I installed the PDO Drive as following

apt install php7.0-sybase

The following is my main-local.php

'db' => [
        'class' => 'yii\db\mssql\PDO',
        'dsn' => 'sqlsrv:Server=xx.xx.xx.xx;Database=xxxx',
        'username' => '<username>',
        'password' => '<password>',
        'charset' => 'utf8'
],

And i got the following error message.

Invalid Configuration – yii\base\InvalidConfigException
Missing required parameter "dsn" when instantiating "yii\db\mssql\PDO".


1. in /var/www/html/ms/vendor/yiisoft/yii2/di/Container.php at line 466

2. in /var/www/html/ms/vendor/yiisoft/yii2/di/Container.php at line 370 – yii\di\Container::resolveDependencies([yii\di\Instance, yii\di\Instance, yii\di\Instance, yii\di\Instance], ReflectionClass)

Seems related to class reflction but I have no idea on how to solve it.

Hope someone can give a help hand on this.

  • 写回答

1条回答

  • dongshi949737 2018-10-10 08:54
    关注

    Try

    'db' => [
        'class' => 'yii\db\Connection',
        'driverName' => 'sqlsrv',
        'dsn' => 'sqlsrv:Server=xx.xx.xx.xx;Database=xxxx',
        'username' => '<username>',
        'password' => '<password>',
        'charset' => 'utf8'
    ],
    
    评论

报告相同问题?

悬赏问题

  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao