Last active
November 7, 2022 10:34
-
-
Save wesolowski/14aef51676880cae5597c1231f6ee5fd to your computer and use it in GitHub Desktop.
Shopware DB-Debug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function _execute(array $params = null) | |
{ | |
try { | |
$start = microtime(true); | |
if ($params !== null) { | |
$ret = $this->_stmt->execute($params); | |
} else { | |
$ret = $this->_stmt->execute(); | |
} | |
$sqlQuery = $this->_stmt->queryString; | |
if (strpos($sqlQuery, 'db_log') === false) { | |
Shopware()->Db()->insert( | |
'db_log', | |
[ | |
'time' => microtime(true) - $start, | |
'ident' => $sqlQuery, | |
'data' => json_encode($params, JSON_PRETTY_PRINT), | |
'trace' => json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), JSON_PRETTY_PRINT), | |
'server' => json_encode($_SERVER, JSON_PRETTY_PRINT), | |
] | |
); | |
} | |
return $ret; | |
} catch (PDOException $e) { | |
require_once 'Zend/Db/Statement/Exception.php'; | |
throw new Zend_Db_Statement_Exception($e->getMessage(), (int)$e->getCode(), $e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function _execute(array $params = null) | |
{ | |
try { | |
$start = microtime(true); | |
if ($params !== null) { | |
$ret = $this->_stmt->execute($params); | |
} else { | |
$ret = $this->_stmt->execute(); | |
} | |
if (!isset($_SERVER['HTTP_USER_AGENT']) || !isset($_SESSION)) { | |
} else { | |
$sqlQuery = $this->_stmt->queryString; | |
if (strpos($sqlQuery, 'db_log') === false) { | |
Shopware()->Db()->insert( | |
'db_log', | |
[ | |
'time' => microtime(true) - $start, | |
'ident' => $sqlQuery, | |
'data' => json_encode($params, JSON_PRETTY_PRINT), | |
'trace' => json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), JSON_PRETTY_PRINT), | |
'server' => json_encode($_SERVER, JSON_PRETTY_PRINT), | |
] | |
); | |
} | |
} | |
return $ret; | |
} catch (PDOException $e) { | |
require_once 'Zend/Db/Statement/Exception.php'; | |
throw new Zend_Db_Statement_Exception($e->getMessage(), (int)$e->getCode(), $e); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE TABLE IF NOT EXISTS `db_log` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`time` double DEFAULT NULL, | |
`ident` text, | |
`data` text, | |
`trace` text, | |
`server` text, | |
PRIMARY KEY (`id`) | |
) ENGINE=MyISAM DEFAULT CHARSET=utf8; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//vendor/doctrine/dbal/lib/Doctrine/DBAL/Configuration.php:60 | |
public function getSQLLogger() | |
{ | |
if ($this->_attributes['sqlLogger'] === null ) { | |
$this->_attributes['sqlLogger'] = new \Doctrine\DBAL\Logging\DebugStack(); | |
} | |
return $this->_attributes['sqlLogger'] ?? null; | |
} | |
// vendor/doctrine/dbal/lib/Doctrine/DBAL/Logging/DebugStack.php:21 | |
public function stopQuery() | |
{ | |
if ($this->enabled) { | |
$this->queries[$this->currentQuery]['executionMS'] = microtime(true) - $this->start; | |
Shopware()->Db()->insert( | |
'db_log', | |
[ | |
'time' => microtime(true) - $this->start, | |
'ident' => $this->queries[$this->currentQuery]['sql'], | |
'data' => json_encode($this->queries[$this->currentQuery]['params'], JSON_PRETTY_PRINT), | |
'trace' => json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), JSON_PRETTY_PRINT), | |
'server' => json_encode($_SERVER, JSON_PRETTY_PRINT), | |
] | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment