|
@@ -1,26 +1,24 @@
|
|
<?php
|
|
<?php
|
|
|
|
|
|
-$pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass');
|
|
|
|
-
|
|
|
|
|
|
+$pdo = new PDO('mysql:host=tfb-database;dbname=hello_world', 'benchmarkdbuser', 'benchmarkdbpass',
|
|
|
|
+ [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]);
|
|
|
|
+$statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
|
|
|
|
+$fortune = $pdo->prepare('SELECT id,message FROM Fortune');
|
|
|
|
|
|
function db()
|
|
function db()
|
|
{
|
|
{
|
|
- global $pdo;
|
|
|
|
|
|
+ global $statement;
|
|
ngx_header_set('Content-Type', 'application/json');
|
|
ngx_header_set('Content-Type', 'application/json');
|
|
|
|
|
|
- $statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
|
|
|
|
-
|
|
|
|
$statement->execute([mt_rand(1, 10000)]);
|
|
$statement->execute([mt_rand(1, 10000)]);
|
|
- echo json_encode($statement->fetch(PDO::FETCH_ASSOC), JSON_NUMERIC_CHECK);
|
|
|
|
|
|
+ echo json_encode($statement->fetch(), JSON_NUMERIC_CHECK);
|
|
}
|
|
}
|
|
|
|
|
|
function query()
|
|
function query()
|
|
{
|
|
{
|
|
- global $pdo;
|
|
|
|
|
|
+ global $statement;
|
|
ngx_header_set('Content-Type', 'application/json');
|
|
ngx_header_set('Content-Type', 'application/json');
|
|
|
|
|
|
- $statement = $pdo->prepare('SELECT id,randomNumber FROM World WHERE id=?');
|
|
|
|
-
|
|
|
|
$query_count = 1;
|
|
$query_count = 1;
|
|
$params = ngx::query_args()['queries'];
|
|
$params = ngx::query_args()['queries'];
|
|
if ($params > 1) {
|
|
if ($params > 1) {
|
|
@@ -29,7 +27,7 @@ function query()
|
|
|
|
|
|
while ($query_count--) {
|
|
while ($query_count--) {
|
|
$statement->execute([mt_rand(1, 10000)]);
|
|
$statement->execute([mt_rand(1, 10000)]);
|
|
- $arr[] = $statement->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
+ $arr[] = $statement->fetch();
|
|
}
|
|
}
|
|
|
|
|
|
echo json_encode($arr, JSON_NUMERIC_CHECK);
|
|
echo json_encode($arr, JSON_NUMERIC_CHECK);
|
|
@@ -65,10 +63,9 @@ function update()
|
|
|
|
|
|
function fortune()
|
|
function fortune()
|
|
{
|
|
{
|
|
- global $pdo;
|
|
|
|
|
|
+ global $fortune;
|
|
ngx_header_set('Content-Type', 'text/html;charset=UTF-8');
|
|
ngx_header_set('Content-Type', 'text/html;charset=UTF-8');
|
|
|
|
|
|
- $fortune = $pdo->prepare('SELECT id,message FROM Fortune');
|
|
|
|
$fortune->execute();
|
|
$fortune->execute();
|
|
|
|
|
|
$arr = $fortune->fetchAll(PDO::FETCH_KEY_PAIR);
|
|
$arr = $fortune->fetchAll(PDO::FETCH_KEY_PAIR);
|