Example #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;
 }