Ejemplo n.º 1
0
 public function getResult()
 {
     if (is_null($this->mysqli)) {
         $this->mysqli = GlobalMas::$mysqli;
     }
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $chk = array("bool" => true, 'traceID' => "getResult");
     $update = false;
     //----------------------------------------------------------
     if ($this->returnQuery) {
         return $this->queryString;
     }
     //----------------------------------------------------------
     $chk = GenFun::debugChk($chk, array("queryString" => $this->queryString));
     //----------------------------------------------------------
     $debug = GlobalMas::$debug;
     //----------------------------------------------------------
     if ($this->chkForQuery) {
         $query_chk = Result::go("SELECT queries.result, queries.last_update FROM queries WHERE queries.query = '" . $this->mysqli->escape_string($this->queryString) . "'");
         //------------------------------------------------------
         if (sizeof($query_chk['result']) > 0) {
             if (empty($query_chk['result'][0]['last_update']) || is_null($query_chk['result'][0]['last_update'])) {
                 $update = true;
             }
             if (!$update) {
                 $chk = json_decode($query_chk['result'][0]['result'], true);
                 //----------------------------------------------
                 $chk = self::debug_chk($chk);
                 //----------------------------------------------
                 return $chk;
             }
         }
     }
     //----------------------------------------------------------
     $result = $this->multi ? $this->mysqli->multi_query($this->queryString) : $this->mysqli->query($this->queryString);
     //----------------------------------------------------------
     if (!$result) {
         $chk['bool'] = false;
         $chk['error'] = false;
         $chk = GenFun::debugCHK($chk, array('message' => $this->mysqli->error));
         if (strpos($chk['message'], "Duplicate") !== false) {
             return $chk['duplicate'] = true;
         }
     }
     //----------------------------------------------------------
     if ($this->multi) {
         $result = $this->getMultiQueryResult($result);
     } else {
         $result = $this->getSingleQueryResult($result);
         //----------------------------------------------
         if ($this->greaterZero) {
             if (sizeof($result) == 0) {
                 $chk['bool'] = false;
             }
         }
     }
     $chk['result'] = $result;
     //----------------------------------------------------------
     $this->insert_id = $this->mysqli->insert_id;
     $chk['insert_id'] = $this->insert_id;
     //--------------------------------------------------
     if ($this->chkForQuery) {
         $queryString = $this->mysqli->real_escape_string($this->queryString);
         $resultString = $this->mysqli->real_escape_string(json_encode($chk));
         if (!$update) {
             $query_chk = Result::go("INSERT INTO queries (query, result)\r\n\t\t\t\t SELECT * FROM (SELECT '" . $queryString . "', '" . $resultString . "') AS tmp\r\n\t\t\t\tWHERE NOT EXISTS (\r\n\t\t\t\t\tSELECT query FROM queries WHERE query = '" . $queryString . "'\r\n\t\t\t\t) LIMIT 1");
         } else {
             $query_chk = Result::go("UPDATE queries SET queries.query = '" . $queryString . "', queries.result = '" . $resultString . "', queries.last_update = NOW() WHERE queries.query = '" . $queryString . "'");
         }
         //----------------------------------------------
         GlobalMas::$debug = $debug;
     }
     //------------------------------------------------------
     $chk = self::debug_chk($chk);
     //------------------------------------------------------
     if ($this->resetQueries) {
         $chk['resetQueries'] = Result::resetQueries();
     }
     //------------------------------------------------------
     return $chk;
 }
Ejemplo n.º 2
0
 public function getResult()
 {
     //----------------------------------------------------------
     //init var
     //----------------------------------------------------------
     $chk = array("bool" => true, 'traceID' => "getResult");
     $update = false;
     //----------------------------------------------------------
     if ($this->returnQuery) {
         return $this->queryString;
     }
     //----------------------------------------------------------
     $chk = GenFun::debugChk($chk, array("queryString" => $this->queryString));
     //----------------------------------------------------------
     $debug = Constants::$debug;
     //----------------------------------------------------------
     if ($this->chkForQuery) {
         $query_chk = Result::go("SELECT queries.result, queries.last_update FROM queries WHERE queries.query = '" . Constants::$mysqli->escape_string($this->queryString) . "'");
         //------------------------------------------------------
         if (sizeof($query_chk['result']) > 0) {
             if (empty($query_chk['result'][0]['last_update']) || is_null($query_chk['result'][0]['last_update'])) {
                 $update = true;
             }
             if (!$update) {
                 $chk = json_decode($query_chk['result'][0]['result'], true);
                 //----------------------------------------------
                 $chk = self::debug_chk($chk);
                 //----------------------------------------------
                 return $chk;
             }
         }
     }
     //----------------------------------------------------------
     $result = $multi ? Constants::$mysqli->multi_query($this->queryString) : Constants::$mysqli->query($this->queryString);
     //----------------------------------------------------------
     if ($result) {
         $chk['bool'] = true;
         $arr = array();
         if ($result) {
             if ($multi) {
                 $result = Constants::$mysqli->use_result();
             }
             //--------------------------------------------------
             if ($result && is_object($result)) {
                 while ($row = $result->fetch_assoc()) {
                     array_push($arr, $row);
                 }
                 //----------------------------------------------
                 if ($this->greaterZero) {
                     if (sizeof($arr) == 0) {
                         $chk['bool'] = false;
                     }
                 }
                 //----------------------------------------------
                 $chk['result'] = $arr;
             }
         }
         //Constants::$debug = false;
         //--------------------------------------------------
         if ($this->chkForQuery) {
             $queryString = Constants::$mysqli->real_escape_string($this->queryString);
             $resultString = Constants::$mysqli->real_escape_string(json_encode($chk));
             if (!$update) {
                 $query_chk = Result::go("INSERT INTO queries (query, result)\n\t\t\t\t\t SELECT * FROM (SELECT '" . $queryString . "', '" . $resultString . "') AS tmp\n\t\t\t\t\tWHERE NOT EXISTS (\n\t\t\t\t\t\tSELECT query FROM queries WHERE query = '" . $queryString . "'\n\t\t\t\t\t) LIMIT 1");
             } else {
                 $query_chk = Result::go("UPDATE queries SET queries.query = '" . $queryString . "', queries.result = '" . $resultString . "', queries.last_update = NOW() WHERE queries.query = '" . $queryString . "'");
             }
             //----------------------------------------------
             Constants::$debug = $debug;
         }
     } else {
         $chk['bool'] = false;
         $chk['error'] = true;
         $chk = GenFun::debugCHK($chk, array('message' => Constants::$mysqli->error));
         if (strpos($chk['message'], "Duplicate") !== false) {
             $chk['duplicate'] = true;
         }
     }
     //------------------------------------------------------
     $chk = self::debug_chk($chk);
     //------------------------------------------------------
     if ($this->resetQueries) {
         $chk['resetQueries'] = $this->resetQueries_CFG();
     }
     //------------------------------------------------------
     return $chk;
 }