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'
    ],
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘