carlosekt / psql_debug
适用于3.x.x版本的Phalcon SQL调试栏
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
适用于3.x.x版本的Phalcon SQL调试栏
支持原生SQL,PHQL,替换Phalcon占位符
它显示查询,查询执行时间,突出显示长查询和错误查询,以及少量系统信息...
安装
- 将Packagist仓库包含到您的项目中。
composer require carlosekt/psql_debug
或者将文件包含到您的代码中
include 'path_to_class' . 'PSQL_Debug.php';
- 在public/index.php中在
define('SYSTEM_START_TIME', microtime(true));
- 在您的配置中添加变量
... 'sql_debug' => true //false ...
- 在echo $application->handle()->getContent();后添加
if ($di->get('config')->sql_debug) { \CarlosEkt\PSQL_Debug::getInstance()->end(microtime(true)); }
- 在loadServices()函数中,设置DI中的DB连接处添加
//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);