/** * 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; } }
/** * Executes a prepared Query * * @link http://php.net/manual/en/mysqli-stmt.execute.php * @return bool "int" (insert_id) by "<b>INSERT / REPLACE</b>"-queries<br /> * "int" (affected_rows) by "<b>UPDATE / DELETE</b>"-queries<br /> * "true" by e.g. "SELECT"-queries<br /> * "false" on error * @since 5.0 */ public function execute() { if ($this->_use_bound_parameters_interpolated === true) { $this->interpolateQuery(); call_user_func_array(array('parent', 'bind_param'), $this->_buildArguments()); } $query_start_time = microtime(true); $result = parent::execute(); $query_duration = microtime(true) - $query_start_time; if ($result === true) { // "INSERT" || "REPLACE" if (preg_match('/^\\s*"?(INSERT|REPLACE)\\s+/i', $this->_sql)) { $insert_id = (int) $this->insert_id; $this->_debug->logQuery($this->_sql_with_bound_parameters, $query_duration, $insert_id); return $insert_id; } // "UPDATE" || "DELETE" if (preg_match('/^\\s*"?(UPDATE|DELETE)\\s+/i', $this->_sql)) { $affected_rows = (int) $this->affected_rows; $this->_debug->logQuery($this->_sql_with_bound_parameters, $query_duration, $affected_rows); return $affected_rows; } // "SELECT" if (preg_match('/^\\s*"?(SELECT)\\s+/i', $this->_sql)) { $num_rows = (int) $this->num_rows; $this->_debug->logQuery($this->_sql_with_bound_parameters, $query_duration, $num_rows); return true; } // log the ? query $this->_debug->logQuery($this->_sql_with_bound_parameters, $query_duration, 0); return true; } // log the error query $this->_debug->logQuery($this->_sql_with_bound_parameters, $query_duration, 0, true); return $this->queryErrorHandling($this->error, $this->_sql_with_bound_parameters); }