$db = new yii\db\Connection([
'dsn' => 'mysql:host=localhost;dbname=example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
]);
return [
// ...
'components' => [
// ...
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=example',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'on afterOpen' => function($event) {
// $event->sender содержит соединение с базой данных
$event->sender->createCommand("SET time_zone = 'UTC'")->execute();
}
],
],
// ...
];
Yii Справочник v0.05 © 2007-2024 Igor Salnikov aka SunDoctor