mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Add support for starting/stopping debug mode DB query logging, enabling you to focus in on logging queries in between specific calls
This commit is contained in:
@@ -882,6 +882,8 @@ function wireClassName($className, $withNamespace = false, $verbose = false) {
|
||||
* }
|
||||
* ~~~~~
|
||||
*
|
||||
* #pw-group-class-helpers
|
||||
*
|
||||
* @param string|object $className
|
||||
* @param bool $withClass Include class name in returned namespace? (default=false)
|
||||
* @param bool $strict Return array of namespaces if multiple match? (default=false)
|
||||
|
@@ -641,21 +641,31 @@ class WireDatabasePDO extends Wire implements WireDatabase {
|
||||
protected function ___unknownColumnError($column) { }
|
||||
|
||||
/**
|
||||
* Log a query, or return logged queries
|
||||
* Log a query, start/stop query logging, or return logged queries
|
||||
*
|
||||
* - To log a query, provide the $sql argument containing the query (string).
|
||||
* - To retrieve the query log, call this method with no arguments.
|
||||
* - Note the core only populates the query log when `$config->debug` mode is active.
|
||||
* - Specify boolean true for $sql argument to reset and start query logging (3.0.173+)
|
||||
* - Specify boolean false for $sql argument to stop query logging (3.0.173+)
|
||||
*
|
||||
* #pw-group-custom
|
||||
*
|
||||
* @param string $sql Query (string) to log
|
||||
* @param string $sql Query (string) to log, boolean true to reset/start query logging, boolean false to stop query logging
|
||||
* @param string $note Any additional debugging notes about the query
|
||||
* @return array|bool|int Returns query log array, boolean true if added, boolean false if not
|
||||
* @return array|bool|int Returns query log array, boolean true on success, boolean false if not
|
||||
*
|
||||
*/
|
||||
public function queryLog($sql = '', $note = '') {
|
||||
if(empty($sql)) return $this->queryLog;
|
||||
if($sql === true) {
|
||||
$this->debugMode = true;
|
||||
$this->queryLog = array();
|
||||
return true;
|
||||
} else if($sql === false) {
|
||||
$this->debugMode = false;
|
||||
return true;
|
||||
}
|
||||
if(!$this->debugMode) return false;
|
||||
if(count($this->queryLog) > $this->queryLogMax) {
|
||||
if(isset($this->queryLog['error'])) {
|
||||
|
Reference in New Issue
Block a user