mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-26 14:26:54 +08:00
Fixes #1522: added example of executing extra queries right after establishing DB connection
This commit is contained in:
@ -72,6 +72,26 @@ $connection->open();
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
> **Tip**: if you need to execute additional SQL queries right after establishing a connection you can add the
|
||||||
|
> following to your application configuration file:
|
||||||
|
>
|
||||||
|
```php
|
||||||
|
return [
|
||||||
|
// ...
|
||||||
|
'components' => [
|
||||||
|
// ...
|
||||||
|
'db' => [
|
||||||
|
'class' => 'yii\db\Connection',
|
||||||
|
// ...
|
||||||
|
'on afterOpen' => function($event) {
|
||||||
|
$event->sender->createCommand("SET time_zone = 'UTC'")->execute();
|
||||||
|
}
|
||||||
|
],
|
||||||
|
],
|
||||||
|
// ...
|
||||||
|
];
|
||||||
|
```
|
||||||
|
|
||||||
Basic SQL queries
|
Basic SQL queries
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user