From 12e6c9bc29109b3c6d104691d872236b17556e22 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Tue, 17 Dec 2013 20:05:19 +0100 Subject: [PATCH] Fixes #1522: added example of executing extra queries right after establishing DB connection --- docs/guide/database-basics.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/guide/database-basics.md b/docs/guide/database-basics.md index 520da22..9354a3d 100644 --- a/docs/guide/database-basics.md +++ b/docs/guide/database-basics.md @@ -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 -----------------