0

i need to set up a yii2 site to connect to a sql server database which is locked behind windows authentication. normally with sql server auth (essentially username/ password) i'd do it like this.

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'sqlsrv:Server=serverip;Database=dbname',
    'username' => 'dbuser'
    'password' => 'samplePassword',
    'charset' => 'utf8',
    'enableSchemaCache' => true,
];

the server configuration would look something like this i think, but this does not work.(basically the same except using windows login / password, since windows authentication gives access to a windows user and then they can just log in to the SQL server database in SSMS without any additional credentials)

return [
    'class' => 'yii\db\Connection',
    'dsn' => 'sqlsrv:Server=serverip;Database=dbname',
    'username' => 'DOMAIN\windowsusername'
    'password' => 'windowsPassword',
    'charset' => 'utf8',
    'enableSchemaCache' => true,
];

Is this even possible? how would one go about configuring this? ( i can't seem to find any official yii2 docs on this)

Andrelope
  • 103
  • 1
  • 11
  • Based on [this](https://learn.microsoft.com/en-us/sql/connect/php/how-to-connect-using-windows-authentication?view=sql-server-2017) it seems that you are not supposed to set username/password when using windows authentication. Yii uses PDO to connect to DB so i would try to set `username` and `password` to `null`. – Michal Hynčica Oct 10 '19 at 16:28
  • 1
    @MuhammadOmerAslam but he is using PDO. What he posted is standard config for `yii\db\Connection` and that uses PDO. – Michal Hynčica Oct 10 '19 at 20:49
  • i totally mixed 2 different posts and added comment here :| my bad. – Muhammad Omer Aslam Oct 10 '19 at 21:33
  • From where did you download the driver ? – Moeez Jul 05 '22 at 09:29

0 Answers0