..., 'params' => ...) public static function matching(string $pattern): array { return array_values(array_filter(self::$log, function ($entry) use ($pattern) { return preg_match($pattern, $entry['sql']); })); } public function __construct(...$args) { self::$connections[] = $args; if (self::$connectError !== NULL) { $this->connect_errno = 1045; $this->connect_error = self::$connectError; } } public function real_escape_string($string) { return addslashes((string)$string); } public function execute_query($sql, $params = array()) { if (substr_count($sql, '?') !== count($params)) throw new \LogicException("Placeholder count does not match the parameters: $sql"); return $this->run($sql, array_values($params)); } public function query($sql) { return $this->run($sql, array()); } public function close() { $this->closed = TRUE; return TRUE; } private function run(string $sql, array $params) { $entry = array('sql' => $sql, 'params' => $params); self::$log[] = $entry; if (self::$logFile !== NULL) file_put_contents(self::$logFile, json_encode($entry) . "\n", FILE_APPEND | LOCK_EX); $answer = NULL; foreach (array_reverse(self::$handlers) as list($pattern, $handler)) { if (preg_match($pattern, $sql)) { $answer = is_callable($handler) ? $handler($sql, $params) : $handler; break; } } if ($answer === NULL) $answer = preg_match('/^\s*SELECT/i', $sql) ? array() : TRUE; if ($answer === FALSE) { $this->error = 'Fake failure for: ' . $sql; return FALSE; } return is_array($answer) ? new FakeResult($answer) : $answer; } }