Example #1
0
        # Order by
        if (isset($_CGET['order'])) {
            $order_sort = isset($_CGET['ordersort']) ? explode(',', $_CGET['ordersort']) : [];
            $query->add_order_by(explode(',', $_CGET['order']), $order_sort);
        }
        # Adding our update columns
        $query->add_update_columns(PostParser::decode());
        # Where columns
        $query->add_where_columns($_CGET);
    }
    # Updating our partition
    $query->set_table($partition_data['table_name'], false, false, $partition_data['database']);
    $update_query = $query->get_update_query($limit, false, false);
    mysqli_sub_query($partition_dblink, $update_query);
    # Getting our updated info
    $info = mysqli_info_array($partition_dblink);
    $limit -= (int) $info['Rows matched'];
    # Tracking our internal changed numbers
    $content->affected_rows += (int) $info['Changed'];
    $content->matched_rows += (int) $info['Rows matched'];
    # We are done updating
    if ($limit !== false && $limit <= 0) {
        break;
    }
}
mysqli_free_result($partition_results);
# Returning our values
PostParser::send($content);
/* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */
# Updating our partition row counts
$size_changed = false;
function mysqli_log_query($dblink, $query, $time, $numrows)
{
    # Making our query one line
    if (NQ_MYSQL_QUERIES_LOG || NQ_MYSQL_QUERIES_PRINT) {
        $query = preg_replace("/[\r\n]+/", ' ', $query);
        $query = preg_replace("/[\t]+/", '', $query);
    }
    # Logging our queries to memory
    global $G_DEBUG_DATA;
    if (NQ_DEBUG_MYSQL_QUERIES) {
        # Our log data
        $log_data = ['query' => trim(preg_replace("/[\r\n]+/", ' ', preg_replace("/[\t]+/", '', $query))), 'time' => $time, 'rows' => $numrows, 'info' => mysqli_info_array($dblink)];
        # Getting explain
        if (NQ_DEBUG_MYSQL_EXPLAIN && substr($log_data['query'], 0, 6) == 'SELECT') {
            $debug_query = 'EXPLAIN EXTENDED ' . $log_data['query'];
            $result = mysqli_multi_result_query($dblink, $debug_query);
            $log_data['explain'] = mysqli_fetch_all($result, MYSQLI_ASSOC);
        }
        # Adding to the debug array
        $G_DEBUG_DATA->mysql_queries[] = $log_data;
    }
    # If we are logging our errors
    if (NQ_MYSQL_QUERIES_LOG) {
        # Writing our error
        $handle = fopen(NQ_MYSQL_LOG_DIRECTORY . '/' . date('Y-m-d') . '.queries.txt', 'a');
        fwrite($handle, date('H:i:s') . ' - ' . str_pad(number_format($time, 5), 9, '0', STR_PAD_LEFT) . ' - ' . $query . "\r\n");
        fclose($handle);
    }
    # Logging slow queries
    if (NQ_MYSQL_QUERIES_LOG_SLOW && NQ_MYSQL_QUERIES_LOG_SLOW_TIME <= $time) {
        # Writing our slow query
        if (NQ_MYSQL_QUERIES_LOG) {
            $handle = fopen(NQ_MYSQL_LOG_DIRECTORY . '/' . date('Y-m-d') . '.slow-queries.txt', 'a');
            fwrite($handle, date('H:i:s') . ' - ' . str_pad(number_format($time, 5), 9, '0', STR_PAD_LEFT) . ' - ' . $query . "\r\n");
            fclose($handle);
        }
        # Sending an email
        if (NQ_MYSQL_QUERIES_EMAIL_SLOW != '') {
            # Including the formatter
            require_once __DIR__ . '/parsers/sqlformatter.php';
            # Mail headers
            $headers = ['From: nuQuery Notification <' . NQ_ADMIN_EMAIL_ADDRESS . '>', 'MIME-Version: 1.0', 'Content-type:text/html;charset=iso-8859-1', 'Reply-To: MYSQL Error Report <' . NQ_MYSQL_ERROR_EMAIL_ADDRESS . '>', 'X-Mailer: PHP/' . phpversion(), 'X-Priority: 5', 'X-MSMail-Priority: Low', 'Importance: Low'];
            $headers = implode("\n", $headers);
            # Mail body
            $body = '	<div style="' . NQ_EMAIL_BLOCK_HEADER . '">
		   					Request Details
		   				</div>
		   				<div style="' . NQ_EMAIL_BLOCK_BODY . '">
		   					<label style="' . NQ_EMAIL_BLOCK_LABEL . '">Local Server ID:</label> ' . NQ_LOCAL_SERVER_ID . '
							<br />
		   					<label style="' . NQ_EMAIL_BLOCK_LABEL . '"> Requested URL:</label > ' . $_SERVER['HTTP_HOST'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'] . '
		   					<br />
		   					<label style="' . NQ_EMAIL_BLOCK_LABEL . '"> Query Time:</label > ' . number_format($time, 3) . ' seconds
		   				</div>
		   				<div style="' . NQ_EMAIL_BLOCK_HEADER . '">
		   					MySQL Query (' . mysqli_get_host_info($dblink) . ')
		   				</div>
		   				<div style="' . NQ_EMAIL_BLOCK_BODY . 'white-space:pre;">' . SqlFormatter::format($query) . '</div>';
            # Sending our mail
            queue_shutdown_email(NQ_MYSQL_ERROR_EMAIL_ADDRESS, 'MYSQL Slow Error Exception', $body, $headers);
        }
    }
}