'\\$', '\\' => '\\\\\\\\', "'" => "''", ]; $p = strtr($p, $replacements); return "'$p'"; } return $p; }, $this->params); $keys = []; $limit = is_int(key($params)) ? 1 : -1; foreach ($params as $key => $param) { $keys[] = is_string($key) ? "/:$key\b/" : '/[?]/'; } return preg_replace($keys, $params, $this->query, $limit); } /** * Get the logging context data for a query. * * @return array */ public function getContext(): array { return [ 'numRows' => $this->numRows, 'took' => $this->took, ]; } /** * Returns data that will be serialized as JSON * * @return array */ public function jsonSerialize(): array { $error = $this->error; if ($error !== null) { $error = [ 'class' => get_class($error), 'message' => $error->getMessage(), 'code' => $error->getCode(), ]; } return [ 'query' => $this->query, 'numRows' => $this->numRows, 'params' => $this->params, 'took' => $this->took, 'error' => $error, ]; } /** * Returns the string representation of this logged query * * @return string */ public function __toString(): string { $sql = $this->query; if (!empty($this->params)) { $sql = $this->interpolate(); } return $sql; } }