# How to set a profiler class to Zend-DB

**URL:** <https://discourse.laminas.dev/t/how-to-set-a-profiler-class-to-zend-db/769>\
**Category:** Components & MVC\
**Tags:** zend-db\
**Created:** [October 7, 2018, 7:32am UTC](https://discourse.laminas.dev/t/how-to-set-a-profiler-class-to-zend-db/769 "2018-10-07T07:32:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![eguvenc](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/eguvenc/32/265_2.png) [@eguvenc](https://discourse.laminas.dev/u/eguvenc)\
**Post date:** [October 7, 2018, 7:32am UTC](https://discourse.laminas.dev/t/how-to-set-a-profiler-class-to-zend-db/769/1 "2018-10-07T07:32:35Z")

</div>

How can it set a profiler class for [https://docs.zendframework.com/zend-db/](https://docs.zendframework.com/zend-db/) component ?

Thanks.

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [October 8, 2018, 6:03am UTC](https://discourse.laminas.dev/t/how-to-set-a-profiler-class-to-zend-db/769/2 "2018-10-08T06:03:58Z")

</div>

zend-db contains a [`Profiler` class](https://github.com/zendframework/zend-db/blob/master/src/Adapter/Profiler/Profiler.php). Basic usage:

```auto
$profiler = new Zend\Db\Adapter\Profiler\Profiler();
$adapter = new Zend\Db\Adapter\Adapter(
    [
        // Driver parameters
    ],
    null, // Platform
    null, // Result prototype
    $profiler
);

$resultSet = $adapter->query(
    'SELECT * FROM album',
    Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
);

var_dump($profiler->getLastProfile());
var_dump($profiler->getProfiles());

```

The adapter can also create a profiler for you:

```auto
$adapter = new Zend\Db\Adapter\Adapter(
    [
        // Driver parameters
       'profiler' => true,
    ]
);

$resultSet = $adapter->query(
    'SELECT * FROM album',
    Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
);

var_dump($adapter->getProfiler()->getLastProfile());
var_dump($adapter->getProfiler()->getProfiles());

```

And with a table gateway:

```auto
$tableGateway = new Zend\Db\TableGateway\TableGateway('album', $adapter // the profiler is set);
$resultSet = $tableGateway->select();

if ($tableGateway->getAdapter() instanceof \Zend\Db\Adapter\Adapter) {
    var_dump($tableGateway->getAdapter()->getProfiler()->getProfiles());
}

```
