Browse Source

fortunes test

ikkez 12 years ago
parent
commit
339670f3be
2 changed files with 12 additions and 6 deletions
  1. 2 2
      php-fatfree/benchmark_config
  2. 10 4
      php-fatfree/index.php

+ 2 - 2
php-fatfree/benchmark_config

@@ -8,7 +8,7 @@
       "db_url": "/db-orm",
       "query_url": "/db-orm/",
       "port": 8080,
-      "sort": 11
+      "sort": 101
     },
     "raw": {
       "setup_file": "setup",
@@ -17,7 +17,7 @@
       "fortune_url": "/fortune",
       "update_url": "/updateraw",
       "port": 8080,
-      "sort": 12
+      "sort": 102
     }
   }]
 }

+ 10 - 4
php-fatfree/index.php

@@ -47,12 +47,13 @@ $f3->route(
         /** @var Base $f3 */
         $params += array('queries' => 1); //default value
         $db = new \DB\SQL('mysql:host=localhost;port=3306;dbname=hello_world',
-            'benchmarkdbuser', 'benchmarkdbpass');
+                          'benchmarkdbuser', 'benchmarkdbpass');
         $mapper = new \DB\SQL\Mapper($db,'World');
         $result = array();
         for ($i = 0; $i < $params['queries']; ++$i) {
             $id = mt_rand(1, 10000);
-            $result[] = $mapper->findone(array('where id = ?',$id))->cast();
+            $mapper->load(array('where id = ?',$id));
+            $result[] = $mapper->cast();
         }
 
         header("Content-type: application/json");
@@ -68,8 +69,13 @@ $f3->route('GET /plaintext', function ($f3) {
 
 $f3->route('GET /fortune', function ($f3) {
     /** @var Base $f3 */
-
-    // to be continued
+    $db = new \DB\SQL('mysql:host=localhost;port=3306;dbname=hello_world',
+                      'benchmarkdbuser', 'benchmarkdbpass');
+    $result = $db->exec('SELECT id, message FROM Fortune');
+    $result[] = 'Additional fortune added at request time.';
+    asort($result);
+    $f3->set('result',$result);
+    echo \Template::instance()->render('fortune.html');
 });