Reputation: 596
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.
Upvotes: 2
Views: 9851
Reputation: 1
below my solution for mssql connection:
from phpinfo() i know that PHP Extension Build API20190902,TS,VC15
then in file php.ini in folder ..\xampp\php insert this
extension=php_pdo_sqlsrv_74_ts_x64.dll extension=php_sqlsrv_74_ts_x64.dll
I have downloaded this dll from microsoft site Put the dll in folder ..\xampp\php\ext
in your framework of yii2, in file ..\basic\config\db.php this is the connection string
'class' => 'yii\db\Connection',
'dsn' => 'sqlsrv:Server=xxxxx\xxxxx;Database=xxxxx',
'username' => 'xxx',
'password' => 'xxxxxxx',
'charset' => 'utf8',
I hope that will be useful. Regards Alessio
Upvotes: 0
Reputation: 18021
Try
'db' => [
'class' => 'yii\db\Connection',
'driverName' => 'sqlsrv',
'dsn' => 'sqlsrv:Server=xx.xx.xx.xx;Database=xxxx',
'username' => '<username>',
'password' => '<password>',
'charset' => 'utf8'
],
Upvotes: 4