Browse Source

Access $pdo when is necessary (#5077)

And not always
Joan Miquel 5 years ago
parent
commit
a83b80650b

+ 2 - 1
frameworks/PHP/workerman/dbraw.php

@@ -1,6 +1,7 @@
 <?php
-function dbraw($pdo)
+function dbraw()
 {
+    global $pdo;
     static $statement;
 
     $statement = $statement ?? $pdo->prepare('SELECT id,randomNumber FROM World WHERE id = ?');

+ 2 - 1
frameworks/PHP/workerman/fortune.php

@@ -1,6 +1,7 @@
 <?php
-function fortune($pdo)
+function fortune()
 {
+    global $pdo;
     static $statement;
     $statement = $statement ?? $pdo->prepare('SELECT id,message FROM Fortune');
     $statement->execute();

+ 3 - 4
frameworks/PHP/workerman/server.php

@@ -14,7 +14,6 @@ $http_worker->onWorkerStart = function () {
         'benchmarkdbuser', 'benchmarkdbpass');
 };
 $http_worker->onMessage = static function ($connection) {
-    global $pdo;
 
     Http::header('Date: '.gmdate('D, d M Y H:i:s').' GMT');
 
@@ -29,15 +28,15 @@ $http_worker->onMessage = static function ($connection) {
 
         case '/db':
             Http::header('Content-Type: application/json');
-            return $connection->send(dbraw($pdo));
+            return $connection->send(dbraw());
 
         case '/fortune':
             Http::header('Content-Type: text/html; charset=utf-8');
-            return $connection->send(fortune($pdo));
+            return $connection->send(fortune());
 
         case '/update':
             Http::header('Content-Type: application/json');
-            return $connection->send(updateraw($pdo));
+            return $connection->send(updateraw());
 
             //case '/info':
             //   Http::header('Content-Type: text/plain');

+ 2 - 1
frameworks/PHP/workerman/updateraw.php

@@ -1,5 +1,6 @@
 <?php
-function updateraw($pdo) {
+function updateraw() {
+  global $pdo;
   $query_count = 1;
   if ($_GET['queries'] > 1) {
     $query_count = min($_GET['queries'], 500);