Skip to content

Latest commit

 

History

History
65 lines (50 loc) · 1.82 KB

profiler.md

File metadata and controls

65 lines (50 loc) · 1.82 KB

Connecting with profiler

Yii DB can be used with Yii Profiler, a tool for collecting and analyzing database queries useful for debugging and optimizing database performance.

When you install Yii Profiler it's automatically configured in the DI container for Yii Config, so you can use it in your application right away.

The following describes how to configure it manually.

Create a file config/common/di/profiler.php.

<?php

declare(strict_types=1);

use Psr\Log\LoggerInterface;
use Yiisoft\Definitions\Reference;
use Yiisoft\Profiler\Profiler;
use Yiisoft\Profiler\ProfilerInterface;

return [
    ProfilerInterface::class => [
        'class' => Profiler::class,
        '__construct()' => [
            Reference::to(LoggerInterface::class),
        ],
    ],
];

Depending on used DBMS, create a file with database connection configuration. For example, when using PostgreSQL, it will be config/common/di/db-pgsql.php:

<?php

declare(strict_types=1);

use Yiisoft\Db\Connection\ConnectionInterface;
use Yiisoft\Db\Pgsql\Connection;
use Yiisoft\Db\Pgsql\Driver;
use Yiisoft\Definitions\Reference;
use Yiisoft\Profiler\ProfilerInterface;

/** @var array $params */

return [
    ConnectionInterface::class => [
        'class' => Connection::class,
        '__construct()' => [
            'driver' => new Driver(
                $params['yiisoft/db-pgsql']['dsn'],
                $params['yiisoft/db-pgsql']['username'],
                $params['yiisoft/db-pgsql']['password'],
            ),
        ],
        'setProfiler()' => [Reference::to(ProfilerInterface::class)],
    ],
];

For other DBMS refer to "Create connecton" section.