carlosekt / psql_debug
Phalcon SQL Debug Bar for version 3.x.x
0.1.1
2018-10-18 08:05 UTC
Requires
- php: >=5.6.0
- ext-phalcon: >=3.2
This package is auto-updated.
Last update: 2024-09-18 21:34:49 UTC
README
Phalcon SQL Debug Bar for version 3.x.x
Support Raw SQL, PHQL, replace phalcon placeholders
It shows queries, queries execution time, highlights long and erroneous queries, plus small system information ...
Installation
- Include packagist repository into your project.
composer require carlosekt/psql_debug
OR include file into your code
include 'path_to_class' . 'PSQL_Debug.php';
- In public/index.php after <?php open tag add:
define('SYSTEM_START_TIME', microtime(true));
- Into your config add variable:
... 'sql_debug' => true //false ...
- After echo $application->handle()->getContent(); add:
if ($di->get('config')->sql_debug) { \CarlosEkt\PSQL_Debug::getInstance()->end(microtime(true)); }
- In loadServices() function, where you set DB connection in DI add:
//Example register a 'db' service in the container $di->set('db', function () use ($config) { $connection = new \Phalcon\Db\Adapter\Pdo\Mysql([ 'host' => $config->database->host, 'username' => $config->database->username, 'password' => $config->database->password, 'dbname' => $config->database->dbname, 'charset' => $config->database->charset ]); if ($config->sql_debug) { $eventsManager = new \Phalcon\Events\Manager(); \CarlosEkt\PSQL_Debug::getInstance()->init(SYSTEM_START_TIME); $eventsManager->attach('db', function ($event) { /** @var Phalcon\Events\Event $event */ if ($event->getType() === 'beforeQuery') { \CarlosEkt\PSQL_Debug::getInstance()->queryStart(microtime(true)); } if ($event->getType() === 'afterQuery') { $sql = \CarlosEkt\PSQL_Debug::getInstance()->getLastQuery(true); \CarlosEkt\PSQL_Debug::getInstance()->queryEnd($sql, microtime(true)); } }); $connection->setEventsManager($eventsManager); } return $connection; }, true);