# How to integrate db-Profiler and log-FirePhp?

**URL:** <https://discourse.laminas.dev/t/how-to-integrate-db-profiler-and-log-firephp/1955>\
**Category:** Components & MVC\
**Tags:** laminas-db\
**Created:** [November 20, 2020, 8:33am UTC](https://discourse.laminas.dev/t/how-to-integrate-db-profiler-and-log-firephp/1955 "2020-11-20T08:33:19Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ZVanoZ](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/zvanoz/32/833_2.png) [@ZVanoZ](https://discourse.laminas.dev/u/ZVanoZ)\
**Post date:** [November 20, 2020, 8:33am UTC](https://discourse.laminas.dev/t/how-to-integrate-db-profiler-and-log-firephp/1955/1 "2020-11-20T08:33:20Z")

</div>

I want to see database queries in browser console by FirePhp extension.

In ZendFramework1 we used: Zend\_Log + Zend\_Log\_Writer\_Firebug + Zend\_Db\_Profiler\_Firebug

Information about queries we can assemble by Laminas\Db\Adapter\Profiler  
Write information into browser we can by \Laminas\Log\Logger + \Laminas\Log\Writer\FirePhp + \Laminas\Log\Formatter\FirePhp

Questions:

1. How integrate Laminas\Db\Adapter\Profiler and \Laminas\Log\Logger?  
Which way the best?  
I think, the best way is catch some event before laminas-mvc send body.  
How to do it?
2. How send tables by chain \Laminas\Log\Logger + \Laminas\Log\Writer\FirePhp + \Laminas\Log\Formatter\FirePhp?  
I possible send text messages only.  
See “testFirePhpDirect” method in sample bellow.

Raw sample:

```
namespace MyApp\Db\Adapter;
class MyAdapter extends \Laminas\Db\Adapter\Adapter
{

    /**
     * @var \Laminas\Log\Logger $logger
     */
    protected $logger;

    /**
     * @var \Laminas\Db\Adapter\Profiler | \BjyProfiler\Db\Profiler\Profiler
     */
    protected $myProfiler;

    public function __construct(array $config)
    {

        $this->initLog();

        $driver = $config;
        /**
         * @type \Laminas\Db\Adapter\Platform\PlatformInterface $platform ;
         */
        $platform = NULL;
        /**
         * @type \Laminas\Db\ResultSet\ResultSetInterface $queryResultPrototype ;
         */
        $queryResultPrototype = NULL;
        /**
         * @type \Laminas\Db\Adapter\Profiler\ProfilerInterface $profiler
         */
        $profiler = new Laminas\Db\Adapter\Profiler() ; // This can define in config a database adapter
        $this->myProfiler = $profiler; // It is a wrong way, but i can't do another. Reason - $this->getProfiler() returns another instance of a profiler.

        parent::__construct($driver, $platform, $queryResultPrototype, $profiler);
    }

    protected function initLog()
    {
        $this->logger = new \Laminas\Log\Logger(); // Creating logger for write any messages

        // Creating Stream writer for write data into a log file.
        $writerStream = new \Laminas\Log\Writer\Stream('data/logs/db.log');
        $this->logger->addWriter($writerStream);

        // Creating FirePhp writer fore write data into browser by http-response-headers
        // In Zend Framework 1 we use Zend_Log_Writer_Firebug
        $writerFirePhp = new \Laminas\Log\Writer\FirePhp(); // Creating log-writer FirePhp for send messsages into browser
        $formatterFirePhp = new \Laminas\Log\Formatter\FirePhp(); // Creating formatter FirePhp. I hope, it can format table, but source code nothing something for it.
        $writerFirePhp->setFormatter($formatterFirePhp);
        $this->logger->addWriter($writerFirePhp); // Add writer into logger. Now we ready to send messages.

        $this->logger->info('this->logger->info'); // This work. Message in log-file and browser console

    }

    function __destruct()
    {
        //$profiler = $this->getProfiler(); 
        //$profiles = $profiler->getProfiles();
        $profiles = $this->myProfiler->getQueryProfiles(); // Ok. We get information about queries.
        $this->logger->info($profiles); // Errors: 1. Now we can't send headers because body already sended; 2. Logger can send text, but $profiles is an array.
    } 

   /** 
    * Sample using FirePhp module for send tables.
    * "firephp/firephp-core": "^0.5.3" @link https://github.com/firephp/firephp-core
    * It is work perfectly. But i want to use Laminas framework native methods.
    *
    * I tested it in:
    * 1. Browser "Firefox Developer Edition"
    * 1.1. Extension "FirePHP" 1.5.7 
    * + Work
    * @link http://firephp.org/
    * @link https://github.com/firephp/firephp-for-browser-devtools
    *
    * 2. Browser "Chromium Version 85.0.4183.121 (Official Build)"
    * 2.1. "FirePHP4Chrome" 0.13
    * ~ Work, but with bugs in formatting.
    * @link https://chrome.google.com/webstore/detail/gpgbmonepdpnacijbbdijfbecmgoojma
    *
    * 2.2 "FirePHP for Chrome" 0.1
    * + Work.
    * @link https://chrome.google.com/webstore/detail/firephp-for-chrome/goajlbdffkligccnfgibeilhdnnpaea
    *
    * 2.3. "firephp-chrome" 0.4.7
    * +Work perfectly. The best extension.
    * @link https://chrome.google.com/webstore/detail/firephp-chrome/aleccmdjeoaihoekgpohjfombpekdghf
    */
   static function testFirePhpDirect()
   {
        $firephp = \FirePHP::getInstance(true);
        $firephp->fb(array('2 SQL queries took 0.06 seconds', array(
            array('SQL Statement', 'Time', 'Result'),
            array('SELECT * FROM Foo', '0.02', array('row1', 'row2')),
            array('SELECT * FROM Bar', '0.04', array('row1', 'row2'))
       )), \FirePHP::TABLE);
    }
}
```
