user2809327
user2809327

Reputation: 157

Yii2 dblib connection charset

I can connect to the database but charset is wrong. It is microsoft server database (mssql).

<?php return array (
  'class' => 'yii\db\Connection',
  'dsn' => 'dblib:host=*******;port=1433;dbname=*******;charset=utf8',
  'username' => '**********',
  'password' => '**********',
  'charset'  => 'utf8',
); ?>

If I use mb_convert_encoding like this then I get right characters but how can I make my connection right?

print_r(mb_convert_encoding($dbString, 'utf-8', "iso-8859-1"));

Upvotes: 0

Views: 1098

Answers (1)

vijay nathji
vijay nathji

Reputation: 1638

First of all on the server check whether the installed drivers php_mssql and php_pdo_mssql or not.

Check the output of phpinfo() to be sure...

 'db'=>array(
        'connectionString' => 'dblib:host=localhost;dbname=test123',
        'emulatePrepare' => false, // comment this if it cause any issue 
        'username' => 'XXXX',
        'password' => 'XXXXX',
        'charset' => 'utf8',
                ),

or Else

May be problem is with the sql server itself, if you uses sqlserver 2000 in which sqlsrv driver may not be compatible check that. if not migrate to sqlserver 2008 or any compitable version might be work smoothly.

Upvotes: 1

Related Questions