Beispiel #1
0
 /**
  * Execute a sql-multi-query.
  *
  * @param string $sql
  *
  * @return false|Result[] "Result"-Array by "<b>SELECT</b>"-queries<br />
  *                        "boolean" by only "<b>INSERT</b>"-queries<br />
  *                        "boolean" by only (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br />
  *                        "boolean" by only by e.g. "DROP"-queries<br />
  *
  * @throws \Exception
  */
 public function multi_query($sql)
 {
     if (!$this->isReady()) {
         return false;
     }
     if (!$sql || $sql === '') {
         $this->_debug->displayError('Can\'t execute an empty Query', false);
         return false;
     }
     $query_start_time = microtime(true);
     $resultTmp = \mysqli_multi_query($this->link, $sql);
     $query_duration = microtime(true) - $query_start_time;
     $this->_debug->logQuery($sql, $query_duration, 0);
     $returnTheResult = false;
     $result = array();
     if ($resultTmp) {
         do {
             $resultTmpInner = \mysqli_store_result($this->link);
             if ($resultTmpInner instanceof \mysqli_result) {
                 $returnTheResult = true;
                 $result[] = new Result($sql, $resultTmpInner);
             } else {
                 $errorMsg = \mysqli_error($this->link);
                 // is the query successful
                 if ($resultTmpInner === true || !$errorMsg) {
                     $result[] = true;
                 } else {
                     $result[] = $this->queryErrorHandling($errorMsg, $sql);
                 }
             }
         } while (\mysqli_more_results($this->link) === true ? \mysqli_next_result($this->link) : false);
     } else {
         $errorMsg = \mysqli_error($this->link);
         if ($this->_debug->checkForDev() === true) {
             echo "Info: maybe you have to increase your 'max_allowed_packet = 30M' in the config: 'my.conf' \n<br />";
             echo 'Error:' . $errorMsg;
         }
         $this->_debug->mailToAdmin('SQL-Error in mysqli_multi_query', $errorMsg . ":\n<br />" . $sql);
     }
     // return the result only if there was a "SELECT"-query
     if ($returnTheResult === true) {
         return $result;
     }
     if (!in_array(false, $result, true)) {
         return true;
     } else {
         return false;
     }
 }