Quellcode durchsuchen

fixed: dao模块中的一些语法错误(在PHP7.3中更严格).

王刚 vor 3 Jahren
Ursprung
Commit
3897f663b0
2 geänderte Dateien mit 23 neuen und 17 gelöschten Zeilen
  1. 11 7
      Gameserver/Amfphp/test.php
  2. 12 10
      Gameserver/Amfphp/util/dao.php

+ 11 - 7
Gameserver/Amfphp/test.php

@@ -18,6 +18,10 @@ echoLine("tsDay:" . totalDays());
 //if ($manager === false) {
 //    CLog::err("MongoDB连接异常!");
 //}
+
+CLog::err("这是一条错误日志!");
+SelfChecker::CheckAll();
+
 // select
 $collection = 'test.ylsj2019taptap';
 $filter = ['key' => ['$regex' => '.*-g$']];
@@ -32,14 +36,14 @@ foreach ($cursor as $document) {
     var_dump($document);
 }
 // insert
-//$collection = "foo.bar";
-//$addArr = ['name' => "王刚1", 'age' => 37];
-//CLog::Assert("insert", gMongo()->insert($collection, $addArr), "插入数据");
-//
+$collection = "foo.bar";
+$addArr = ['name' => "王刚1", 'age' => 37];
+CLog::Assert("insert", gMongo()->insert($collection, $addArr), "插入数据");
+
 //// delete
-//$collection = "foo.bar";
-//$deletFilter = ['name' => "王刚1"];
-//echoLine("删除" . gMongo()->delete($collection, $deletFilter) . "条");
+$collection = "foo.bar";
+$deletFilter = ['name' => "王刚1"];
+echoLine("删除" . gMongo()->delete($collection, $deletFilter) . "条");
 // update
 $collection = "foo.bar";
 $updateFilter = ['Name' => "王刚(wanggangzero@qq.com)1"];

+ 12 - 10
Gameserver/Amfphp/util/dao.php

@@ -58,6 +58,7 @@
 namespace loyalsoft;
 
 use \PDO;
+use \PDOException;
 
 /**
  * DAO, data access object.
@@ -170,7 +171,7 @@ class dao {
      * @return void
      */
     public function __construct() {
-
+        
     }
 
     /**
@@ -342,7 +343,7 @@ class dao {
         /* Get the records count. */
         try {
             $row = $this->dbh->query($sql)->fetch(PDO::FETCH_OBJ);
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             $this->sqlError($e);
         }
 //        CLogUtil_HP::paylog($sql);
@@ -572,8 +573,9 @@ class dao {
      * @return object   the PDOStatement object.
      */
     public function query($sql = '') {
-        if (!empty(dao::$errors))
+        if (!empty(dao::$errors)) {
             return new PDOStatement();   // If any error, return an empty statement object to make sure the remain method to execute.
+        }
 
         if ($sql) {
             if (is_null($this->sqlobj)) {
@@ -592,7 +594,7 @@ class dao {
             } else {
                 return $this->dbh->query($sql);
             }
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             $this->sqlError($e);
         }
     }
@@ -631,7 +633,7 @@ class dao {
             /* Get the records count. */
             try {
                 $row = $this->dbh->query($sql)->fetch(PDO::FETCH_OBJ);
-            } catch (PDOException $e) {
+            } catch (\PDOException $e) {
                 $this->sqlError($e);
             }
 
@@ -674,7 +676,7 @@ class dao {
         try {
             $this->reset();
             return $this->dbh->exec($sql);
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             $this->sqlError($e);
         }
     }
@@ -975,14 +977,14 @@ class dao {
     public function tableExist($tableName) {
         $this->reset();
         $this->setMethod('select');
-        $sql = "SELECT 1 FROM $tableName LIMIT 1";
+        $sql = "SELECT 1 FROM `$tableName` LIMIT 1";
         try {
             if ($this->slaveDBH and $this->method == 'select') {
                 $ret = $this->slaveDBH->query($sql)->fetch();
             } else {
                 $ret = $this->dbh->query($sql)->fetch();
             }
-        } catch (Exception $exc) {
+        } catch (\Exception $exc) {
             return false;
         }
         // Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
@@ -992,7 +994,7 @@ class dao {
     public function Ping() {
         try {
             $this->dbh->getAttribute(PDO::ATTR_SERVER_INFO);
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             if (strpos($e->getMessage(), 'MySQL server has gone away') !== false) {
                 return false;
             }
@@ -1086,7 +1088,7 @@ class dao {
             $sql = "DESC $this->table";
             $rawFields = $this->dbh->query($sql)->fetchAll();
             $this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
-        } catch (PDOException $e) {
+        } catch (\PDOException $e) {
             $this->sqlError($e);
         }