I have two database connections defined:
db:
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=test',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'enableSchemaCache' => true,
'schemaCacheDuration' => 3600,
'schemaCache' => 'cache',
];
dbWithoutUtf8:
<?php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=test',
'username' => 'root',
'password' => 'root',
'charset' => 'latin1',
'enableSchemaCache' => true,
'schemaCacheDuration' => 3600,
'schemaCache' => 'cache',
];
Inside my web.php I am including both:
'dbWithoutUtf8' => require(__DIR__ . '/dbWithoutUtf8.php'),
'db' => require(__DIR__ . '/db.php'),
And in my AR model I am overriding getDb method:
public static function getDb()
{
return Yii::$app->dbWithoutUtf8;
}
In same model I have query that is using db connection insted of dbWithoutUtf8. Any clues why ?
public static function getNews()
{
return self::find()->joinWIth(['document'])->all();
}