function LoggedStatementsTrait::query

Same name in other branches
  1. 8.9.x core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php \Drupal\database_statement_monitoring_test\LoggedStatementsTrait::query()
  2. 10 core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php \Drupal\database_statement_monitoring_test\LoggedStatementsTrait::query()

File

core/modules/system/tests/modules/database_statement_monitoring_test/src/LoggedStatementsTrait.php, line 20

Class

LoggedStatementsTrait
Trait for Connection classes that can store logged statements.

Namespace

Drupal\database_statement_monitoring_test

Code

public function query($query, array $args = [], $options = []) {
    // Log the query if it is a string, can receive statement objects e.g
    // in the pgsql driver. These are hard to log as the table name has already
    // been replaced.
    if (is_string($query)) {
        $stringified_args = array_map(function ($v) {
            return is_array($v) ? implode(',', $v) : $v;
        }, $args);
        $this->loggedStatements[] = str_replace(array_keys($stringified_args), array_values($stringified_args), $query);
    }
    return parent::query($query, $args, $options);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.