pdo = new PDO( 'mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass', [ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false ] ); $this->world = $this->pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?'); $this->fortune = $this->pdo->prepare('SELECT id,message FROM Fortune'); $this->update = $this->pdo->prepare('UPDATE World SET randomNumber=? WHERE id=?'); } function db(): array { $this->world->execute([mt_rand(1, 10000)]); return $this->world->fetch(); } function query($request): array { $query_count = 1; $q = (int)$request->get('q'); if ($q > 1) { $query_count = min($q, 500); } $arr = []; while ($query_count--) { $this->world->execute([mt_rand(1, 10000)]); $arr[] = $this->world->fetch(); } return $arr; } function update($request): array { $query_count = 1; $q = (int)$request->get('q'); if ($q > 1) { $query_count = min($q, 500); } $arr = []; while ($query_count--) { $id = mt_rand(1, 10000); $this->world->execute([$id]); $item = $this->world->fetch(); $this->update->execute( [$item['randomNumber'] = mt_rand(1, 10000), $id] ); $arr[] = $item; } return $arr; } function fortune(): string { $this->fortune->execute(); $arr = $this->fortune->fetchAll(PDO::FETCH_KEY_PAIR); $arr[0] = 'Additional fortune added at request time.'; asort($arr); $html = ''; foreach ($arr as $id => $message) { $message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); $html .= "$id$message"; } return "Fortunes$html
idmessage
"; } }