当前位置: 首页>>代码示例>>PHP>>正文


PHP mysqli_sub_query函数代码示例

本文整理汇总了PHP中mysqli_sub_query函数的典型用法代码示例。如果您正苦于以下问题:PHP mysqli_sub_query函数的具体用法?PHP mysqli_sub_query怎么用?PHP mysqli_sub_query使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了mysqli_sub_query函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: date

        # Getting our general count data
        $query = "\tSELECT\n\t\t\t\t\t\tCOUNT(*) AS `count`,\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`environment`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_TRACKING_DATABASE . ".`api_calls_" . $table . "`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`created`>='" . date('Y-m-d 00:00:00', $date) . "' AND\n\t\t\t\t\t\t`created`<='" . date('Y-m-d 23:59:59', $date) . "'\n\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`environment`";
        $result = mysqli_multi_result_query($G_CONTROLLER_DBLINK, $query);
        while ($count_data = mysqli_fetch_array($result)) {
            # Adding our count into the database
            $query = "\tINSERT IGNORE INTO\n\t\t\t\t\t\t\t" . NQ_TRACKING_DATABASE . ".`api_calls_" . $table . "_summary`\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`app_id`\t=" . $count_data['app_id'] . ",\n\t\t\t\t\t\t\t`environment`\t='" . $count_data['environment'] . "',\n\t\t\t\t\t\t\t`transactions`\t=" . $count_data['count'] . ",\n\t\t\t\t\t\t\t`created`\t='" . date('Y-m-d', $date) . "'";
            mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
        }
        # Getting our general count data
        $query = "\tSELECT\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`type`,\n\t\t\t\t\t\t`environment`,\n\t\t\t\t\t\tCOUNT(*) AS `count`,\n\t\t\t\t\t\tMIN(`size`) AS `min_size`,\n\t\t\t\t\t\tAVG(`size`) AS `avg_size`,\n\t\t\t\t\t\tMAX(`size`) AS `max_size`,\n\t\t\t\t\t\tMIN(`time`) AS `min_time`,\n\t\t\t\t\t\tAVG(`time`) AS `avg_time`,\n\t\t\t\t\t\tMAX(`time`) AS `max_time`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_TRACKING_DATABASE . ".`api_calls_" . $table . "`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`created`>='" . date('Y-m-d 00:00:00', $date) . "' AND\n\t\t\t\t\t\t`created`<='" . date('Y-m-d 23:59:59', $date) . "'\n\t\t\t\t\tGROUP BY\n\t\t\t\t\t\t`app_id`,\n\t\t\t\t\t\t`type`,\n\t\t\t\t\t\t`environment`";
        $result = mysqli_multi_result_query($G_CONTROLLER_DBLINK, $query);
        while ($count_data = mysqli_fetch_array($result)) {
            # Adding our count into the database
            $query = "\tINSERT IGNORE INTO\n\t\t\t\t\t\t\t" . NQ_TRACKING_DATABASE . ".`api_calls_" . $table . "_summary_expanded`\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`app_id`\t\t=" . (int) $count_data['app_id'] . ",\n\t\t\t\t\t\t\t`environment`\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $count_data['environment']) . "',\n\t\t\t\t\t\t\t`type`\t\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, $count_data['type']) . "',\n\t\t\t\t\t\t\t`transactions`\t\t=" . (int) $count_data['count'] . ",\n\t\t\t\t\t\t\t`created`\t\t='" . mysqli_escape_string($G_CONTROLLER_DBLINK, date('Y-m-d', $date)) . "',\n\t\t\t\t\t\t\t`min_size`\t\t=" . (double) $count_data['min_size'] . ",\n\t\t\t\t\t\t\t`avg_size`\t\t=" . (double) $count_data['avg_size'] . ",\n\t\t\t\t\t\t\t`max_size`\t\t=" . (double) $count_data['max_size'] . ",\n\t\t\t\t\t\t\t`min_time`\t\t=" . (double) $count_data['min_time'] . ",\n\t\t\t\t\t\t\t`avg_time`\t\t=" . (double) $count_data['avg_time'] . ",\n\t\t\t\t\t\t\t`max_time`\t\t=" . (double) $count_data['max_time'];
            mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
        }
        # Removing our old entries
        $query = "\tDELETE FROM\n\t\t\t\t\t\t" . NQ_TRACKING_DATABASE . ".`api_calls_" . $table . "`\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`created`>='" . date('Y-m-d 00:00:00', $date) . "' AND\n\t\t\t\t\t\t`created`<='" . date('Y-m-d 23:59:59', $date) . "'";
        mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
        # Message
        if (!NQ_MOD_TRACKING_QUIET) {
            echo 'Summary complete for ', $table, ' on for date ', date('m/d/Y', $date), "\n";
        }
        # Move back a day
        $date -= 24 * 60 * 60;
    }
}
# Message
if (!NQ_MOD_TRACKING_QUIET) {
    echo NQ_MOD_REPORT_SEPARATOR;
}
开发者ID:nuQuery,项目名称:v1m0-cron,代码行数:31,代码来源:summary.php

示例2: CONVERT

    # We have a different size
    $this_size_changed = false;
    if ((int) $partition->data['size'] != (int) $size_data['size']) {
        # Flag size changed
        $size_changed = true;
        $this_size_changed = true;
        # Storing the currently saved size
        $update_queries[] = "\tSET @size_delta = \t(\n\t\t\t\t\t\t\t\t\t\tSELECT \n\t\t\t\t\t\t\t\t\t\t" . (int) $size_data['size'] . "- CONVERT(`size`,SIGNED)\n\t\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t\t`id`=" . (int) $id . "\n\t\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t\t)";
        # Updating our size change
        $update_queries[] = "\tSET @table_size_delta = @table_size_delta + @size_delta";
    }
    # Updating the partitions size
    $update_queries[] = "\tUPDATE\n\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t" . ($this_size_changed ? "`size` = `size` + @size_delta," : "") . "\n\t\t\t\t\t\t`modified`\t=NOW(),\n\t\t\t\t\t\t`accessed`\t=NOW()\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t=" . (int) $id . "\n\t\t\t\t\tLIMIT 1";
}
# Updating the table
$update_queries[] = "\tUPDATE\n\t\t\t\t\t" . NQ_TABLE_SETTINGS_TABLE . "\n\t\t\t\tSET\n\t\t\t\t\t" . ($size_changed ? "`size` = `size` + @table_size_delta," : "") . "\n\t\t\t\t\t`modified`\t=NOW(),\n\t\t\t\t\t`accessed`\t=NOW()\n\t\t\t\tWHERE\n\t\t\t\t\t`id`\t\t=" . (int) $G_TABLE_DETAILS['id'] . "\n\t\t\t\tLIMIT 1";
# Adjusting our app database size
if ($size_changed) {
    $update_queries[] = "\tUPDATE\n\t\t\t\t\t\t" . NQ_APPS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`db_size`=`db_size`+ @table_size_delta\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`=" . (int) $G_APP_DATA['id'] . "\n\t\t\t\t\tLIMIT 1";
}
# Running our update queries
mysqli_multi_sub_query($G_CONTROLLER_DBLINK, implode(';', $update_queries));
# Opening our tracking dblink
$G_TRACKING_DBLINK = mysqli_shared_connect(NQ_TRACKING_HOST, NQ_TRACKING_USERNAME, NQ_TRACKING_PASSWORD, $G_SHARED_DBLINKS);
# Closing the controller dblink
mysqli_shared_close($G_CONTROLLER_DBLINK, $G_SHARED_DBLINKS);
# Adding table analytics
$query = "\tINSERT INTO\n\t\t\t\t" . NQ_TRACKING_TABLE_IO . "\n\t\t\tSET\n\t\t\t\t`app_id`\t=" . (int) $G_APP_DATA['id'] . ",\n\t\t\t\t`table_id`\t=" . (int) $G_TABLE_DETAILS['id'] . ",\n\t\t\t\t`environment`\t='" . mysqli_escape_string($G_TRACKING_DBLINK, $G_APP_ENVIRONMENT) . "',\n\t\t\t\t`writes`\t=1,\n\t\t\t\t`write_rows`\t=" . (int) $content->affected_rows . ",\n\t\t\t\t`created`\t='" . date('Y-m-d H:00:00') . "'";
mysqli_sub_query($G_TRACKING_DBLINK, $query);
# Adding our usage - Always call this last
track_endpoint($G_SHARED_DBLINKS, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $_ENDPOINT);
开发者ID:nuQuery,项目名称:v1m0-api-all,代码行数:31,代码来源:update.php

示例3: queue_email

function queue_email($controller_dblink, $to, $from, $subject, $email_data, $constants, $variables, $app_id, $send_date, $bcc_available = true)
{
    # Reply to
    $reply_to = $from;
    # Separating for validation
    $p = explode('@', $to, 2);
    # Bailing if not someone@someplace.com format
    if (count($p) < 2) {
        return false;
    }
    # Checking if the email is blocked
    $query = "\tSELECT\n\t\t\t\t\t\t`email`\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_BLOCKED_EMAILS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . " AND\n\t\t\t\t\t\t`email`\t='" . mysqli_escape_string($controller_dblink, $to) . "'\n\t\t\t\t\tLIMIT 1";
    $blocked_data = mysqli_single_result_query($controller_dblink, $query);
    # This user has blocked the app from sending emails
    if (isset($blocked_data)) {
        # Adding our analytics
        $query = "\tINSERT INTO\n\t\t\t\t\t\t\t" . NQ_ANALYTICS_BLOCKED_TABLE . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`app_id`\t\t=" . (int) $app_id . ",\n\t\t\t\t\t\t\t`template_id`\t=" . (int) $email_data['id'] . ",\n\t\t\t\t\t\t\t`sender`\t\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t\t`recipient`\t='" . mysqli_escape_string($controller_dblink, $to) . "',\n\t\t\t\t\t\t\t`created`\t\t=NOW()";
        mysqli_sub_query($controller_dblink, $query);
        # Blocked
        return -1;
    } else {
        # Applying our constants and variables
        $attachments_list = [];
        $body = TemplateParser::parse($email_data['body'], $constants, $variables, $app_id, $attachments_list);
        # Applying our unsubscribe
        if ($email_data['requires_unsubscribe'] == 1 && strpos($body, '%unsubscribe%') === false) {
            $body .= '	<div style="margin-top:10px;">%unsubscribe% from ' . $G_APP_DATA['name'] . '</div>';
        }
        # If we are going to track
        $mail_body = $body;
        $bcc_body = $body;
        # Adding our analytics
        $query = "\tINSERT INTO\n\t\t\t\t\t\t" . NQ_ANALYTICS_SENT_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`app_id`\t\t=" . (int) $app_id . ",\n\t\t\t\t\t\t`template_id`\t\t=" . (int) $email_data['id'] . ",\n\t\t\t\t\t\t`sender`\t\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t`recipient`\t\t='" . mysqli_escape_string($controller_dblink, $to) . "',\n\t\t\t\t\t\t`created`\t\t=NOW(),\n\t\t\t\t\t\t`requested_date`\t=NOW()";
        mysqli_sub_query($controller_dblink, $query);
        $analytics_id = mysqli_insert_id($controller_dblink);
        # If we are going to track
        $mail_body = $body;
        $bcc_body = $body;
        if ($email_data['track'] == 1) {
            # Our ids
            $hash_id = hash('sha256', $analytics_id . $to);
            # Updating the hash id
            $query = "\tUPDATE\n\t\t\t\t\t\t\t" . NQ_ANALYTICS_SENT_TABLE . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`hash_id`\t='" . $hash_id . "'\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t`id`\t\t=" . (int) $analytics_id . "\n\t\t\t\t\t\tLIMIT 1";
            mysqli_sub_query($controller_dblink, $query);
            # Customizing the body
            $mail_body .= '<img style="display:none;" src="' . NQ_DOMAIN_ROOT . '/' . $app_id . '/track?ref=' . $hash_id . '" width="1" height="1" />';
        }
        # Inserting our unsubscribe link
        $keys = ['/%unsubscribe%/'];
        $values = ['<a href="' . NQ_DOMAIN_ROOT . '/' . $app_id . '/unsubscribe?ref=' . $hash_id . '&email=' . urlencode($to) . '" style="color:inherit;text-decoration:inherit;"> Unsubscribe </a>'];
        $mail_body = preg_replace($keys, $values, $mail_body);
        # Adding to the queue
        $query = "\tINSERT INTO\n\t\t\t\t\t\t" . NQ_QUEUE_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . ",\n\t\t\t\t\t\t`analytics_id`\t=" . (int) $analytics_id . ",\n\t\t\t\t\t\t`sender`\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t`recipient`\t='" . mysqli_escape_string($controller_dblink, $to) . "',\n\t\t\t\t\t\t`subject`\t='" . mysqli_escape_string($controller_dblink, $subject) . "',\n\t\t\t\t\t\t`raw`\t\t='" . mysqli_escape_string($controller_dblink, build_raw_email($to, $from, $reply_to, $subject, $mail_body, $attachments_list, $app_id)) . "',\n\t\t\t\t\t\t`send_date`\t='" . date('Y-m-d H:i:s', $send_date) . "',\n\t\t\t\t\t\t`priority`\t=1";
        mysqli_sub_query($controller_dblink, $query);
        # Sending the bcc
        if ($bcc_available) {
            # Modifying to add our bcc header
            $bcc_body = trim('<div style="padding:10px;border-bottom:solid #E9E9E9 1px;margin-bottom:1px;line-height:2.0;">
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;"></div><b>BCC Email</b><br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">sent to:</div>' . $to . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">from:</div>' . htmlentities($from) . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">date:</div>' . date('r') . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">send date:</div>' . date('r', $send_date) . '<br />
									<div style="width:75px;color:#999;display:inline-block;text-align:right;padding-right:10px;">tracking:</div>' . ($email_data['track'] == 1 ? 'Yes' : 'No') . '<br />
								</div>
								' . $bcc_body);
            # Sending bcc emails
            foreach (explode(',', $email_data['bcc']) as $bcc) {
                # Adding to the queue
                if (trim($bcc) != '') {
                    $query = "\tINSERT INTO\n\t\t\t\t\t\t\t\t\t" . NQ_QUEUE_TABLE . "\n\t\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . ",\n\t\t\t\t\t\t\t\t\t`sender`\t='" . mysqli_escape_string($controller_dblink, $from) . "',\n\t\t\t\t\t\t\t\t\t`recipient`\t='" . mysqli_escape_string($controller_dblink, trim($bcc)) . "',\n\t\t\t\t\t\t\t\t\t`subject`\t='" . mysqli_escape_string($controller_dblink, $subject) . "',\n\t\t\t\t\t\t\t\t\t`raw`\t\t='" . mysqli_escape_string($controller_dblink, build_raw_email(trim($bcc), $from, $reply_to, $subject, $bcc_body, $attachments_list, $app_id)) . "',\n\t\t\t\t\t\t\t\t\t`send_date`\t=NOW(),\n\t\t\t\t\t\t\t\t\t`priority`\t=255";
                    mysqli_sub_query($controller_dblink, $query);
                }
            }
        }
        # Sent
        return 1;
    }
}
开发者ID:nuQuery,项目名称:v1m0-api-email,代码行数:79,代码来源:functions.php

示例4: mysqli_multi_result_query

                        break;
                        # Dropping an index
                    # Dropping an index
                    case 'drop':
                        # Getting our index
                        $query = "SHOW INDEX FROM " . NQ_DATABASE_STORAGE_DATABASE . ".`" . NQ_DATABASE_STRUCTURE_PREFIX . $G_APP_DATA['id'] . "_" . $G_TABLE_DETAILS['id'] . "`";
                        $result = mysqli_multi_result_query($G_CONTROLLER_DBLINK, $query);
                        while ($index_data = mysqli_fetch_assoc($result)) {
                            # Found the index
                            if ($index_data['Key_name'] == $index->name) {
                                # Dropping the index
                                $query = "\tDROP INDEX\n\t\t\t\t\t\t\t\t\t\t\t\t`" . mysqli_escape_string($G_CONTROLLER_DBLINK, $index->name) . "`\n\t\t\t\t\t\t\t\t\t\t\tON\n\t\t\t\t\t\t\t\t\t\t\t" . NQ_DATABASE_STORAGE_DATABASE . ".`" . NQ_DATABASE_STRUCTURE_PREFIX . $G_APP_DATA['id'] . "_" . $G_TABLE_DETAILS['id'] . "`";
                                mysqli_sub_query($G_CONTROLLER_DBLINK, $query);
                                # Dropping the index from the partitions
                                foreach ($G_TABLE_PARTITIONS as $partition) {
                                    $query = "\tDROP INDEX\n\t\t\t\t\t\t\t\t\t\t\t\t\t`" . mysqli_escape_string($partition['dblink'], $index->name) . "`\n\t\t\t\t\t\t\t\t\t\t\t\tON\n\t\t\t\t\t\t\t\t\t\t\t\t\t`" . $partition['database'] . "`.`" . $partition['table_name'] . "`";
                                    mysqli_sub_query($partition['dblink'], $query, true);
                                }
                                break;
                            }
                        }
                        break;
                }
            }
        }
}
# Returning our values
$strlen = PostParser::send($content);
/* --- Connection closed wit PostParser::send --- Below this point things need to be tracked and cleaned up --- */
# Adding our usage - Always call this last
track_endpoint($G_SHARED_DBLINKS, $G_APP_DATA['id'], $G_APP_ENVIRONMENT, $_ENDPOINT, $strlen);
开发者ID:nuQuery,项目名称:v1m0-api-all,代码行数:31,代码来源:table.php

示例5: directory_hierarchy

function directory_hierarchy($dblink, $app_id, $environment, $dirpath, $autocreate = false)
{
    # Starting properties
    $parent_ids = [];
    $parent_id = 0;
    $path = '~';
    $dir = explode('/', $dirpath);
    # Checking for our root folder
    if ($dir[0] == '~') {
        array_shift($dir);
        array_unshift($dir, '');
    }
    # Looping through our dirs to create
    for ($i = 0, $len = count($dir); $i < $len; $i++) {
        # Saving our name
        $name = $dir[$i];
        if ($name == '' && $i > 0) {
            continue;
        }
        # Checking to see if our path exists
        $query = "\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . " AND\n\t\t\t\t\t\t`environment`\t='" . mysqli_escape_string($dblink, $environment) . "' AND\n\t\t\t\t\t\t`path`\t\t='" . mysqli_escape_string($dblink, $path) . "' AND\n\t\t\t\t\t\t`name`\t\t='" . mysqli_escape_string($dblink, str_replace(str_split(NQ_INVALID_PATH_CHARS), '', $name)) . "'\n\t\t\t\t\tLIMIT 1";
        $directory_data = mysqli_single_result_query($dblink, $query);
        # If it doesn't we add it
        if (!isset($directory_data['id'])) {
            # We can't autocreate
            if (!$autocreate && false && $i > 0) {
                exit_fail(NQ_ERROR_INVALID_VALUE, LANG_INVALID_DIR);
            }
            # Updating our parent
            if ($parent_id > 0) {
                $query = "\tUPDATE\n\t\t\t\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t\t`directories`=`directories`+1\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t`id`=" . (int) $parent_id . "\n\t\t\t\t\t\t\tLIMIT 1";
                mysqli_sub_query($dblink, $query);
            }
            # Adding our directory
            $query = "\tINSERT INTO\n\t\t\t\t\t\t\t" . NQ_DIRECTORY_TABLE . "\n\t\t\t\t\t\tSET\n\t\t\t\t\t\t\t`app_id`\t\t=" . (int) $app_id . ",\n\t\t\t\t\t\t\t`environment`\t\t='" . mysqli_escape_string($dblink, $environment) . "',\n\t\t\t\t\t\t\t`name`\t\t\t='" . mysqli_escape_string($dblink, str_replace(str_split(NQ_INVALID_PATH_CHARS), '', $name)) . "',\n\t\t\t\t\t\t\t`path`\t\t\t='" . mysqli_escape_string($dblink, $path) . "',\n\t\t\t\t\t\t\t`parent_directory_id`\t=" . (int) $parent_id . ",\n\t\t\t\t\t\t\t`created`\t\t=NOW(),\n\t\t\t\t\t\t\t`modified`\t\t=NOW()";
            mysqli_sub_query($dblink, $query);
            $parent_id = mysqli_insert_id($dblink);
        } else {
            $parent_id = $directory_data['id'];
        }
        # Adding to our path
        $parent_ids[] = $parent_id;
        $path .= str_replace(str_split(NQ_INVALID_PATH_CHARS), '', $name) . '/';
    }
    # Removing our last parent id (actual folder id )
    $parent_id = array_pop($parent_ids);
    # Returning our data
    return ['id' => $parent_id, 'path' => $path, 'parent_ids' => $parent_ids];
}
开发者ID:nuQuery,项目名称:v1m0-api-all,代码行数:49,代码来源:functions.php

示例6: get_table_partition

function get_table_partition($controller_dblink, $storage_dblink, $app_data, $table_data, $record_data, $bitmask, &$partition_stack, &$dbstack)
{
    # Calculating our evaluation value
    $evaluation = get_table_partition_evaluation($table_data, $record_data);
    # Checking if we have already selected this partition
    foreach ($partition_stack as $partition) {
        if ($partition->data['table_id'] == $table_data['id'] && $partition->data['evaluation'] == $evaluation) {
            return $partition;
        }
    }
    # Getting our partition
    $query = "\tSELECT\n\t\t\t\t\t*\n\t\t\t\tFROM\n\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\tWHERE\n\t\t\t\t\t`table_id`\t\t=" . (int) $table_data['id'] . " AND\n\t\t\t\t\t`evaluation`\t\t='" . mysqli_escape_string($controller_dblink, $evaluation) . "'\n\t\t\t\tLIMIT 1";
    $partition_data = mysqli_single_result_query($controller_dblink, $query);
    # Bad partition, need to create a new one
    if (!isset($partition_data['table_id'])) {
        # Check if we have partitions available
        if ($bitmask[1] == 0 && $table_data['partitions'] > 0 || $bitmask[1] > 0 && $table_data['partitions'] + 1 > bindec(str_repeat('1', $bitmask[1]))) {
            return false;
        }
        # Inserting the new partition
        $query = "\tLOCK TABLE " . NQ_TABLE_PARTITIONS_TABLE . " WRITE;\n\t\t\t\t\tSET @partition_number=\t(\n\t\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\t\tCOUNT(*)\n\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t`table_id`\t=" . (int) $table_data['id'] . "\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\tSET @id=\t\t(\n\t\t\t\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\t\t\t\t`id`\n\t\t\t\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\t\t\t`table_id`\t=" . (int) $table_data['id'] . " AND\n\t\t\t\t\t\t\t\t\t\t`evaluation`\t='" . mysqli_escape_string($controller_dblink, $evaluation) . "'\n\t\t\t\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\tINSERT INTO\n\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`id`\t\t=IF(ISNULL(@id),NULL,@id),\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_data['id'] . ",\n\t\t\t\t\t\t`table_id`\t=" . (int) $table_data['id'] . ",\n\t\t\t\t\t\t`number`\t=@partition_number,\n\t\t\t\t\t\t`evaluation`\t='" . mysqli_escape_string($controller_dblink, $evaluation) . "',\n\t\t\t\t\t\t`created`\t=NOW(),\n\t\t\t\t\t\t`modified`\t=NOW(),\n\t\t\t\t\t\t`accessed`\t=NOW();\n\t\t\t\t\tUNLOCK TABLES";
        mysqli_multi_sub_query($controller_dblink, $query);
        # Getting our partition
        $query = "\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`table_id`\t=" . (int) $table_data['id'] . " AND\n\t\t\t\t\t\t`evaluation`\t='" . mysqli_escape_string($controller_dblink, $evaluation) . "'\n\t\t\t\t\tLIMIT 1";
        $partition_data = mysqli_single_result_query($controller_dblink, $query);
        # Creating our partition id table
        $create_query = "CREATE TABLE IF NOT EXISTS " . NQ_DATABASE_STORAGE_DATABASE . ".`" . NQ_DATABASE_PARTITION_PREFIX . $app_data['id'] . "_" . $table_data['id'] . "_" . $partition_data['number'] . "`\n\t\t\t\t\t\t\t(\n\t\t\t\t\t\t\t\t`id` " . (array_sum($bitmask) > 32 ? 'BIGINT' : 'INT') . " UNSIGNED AUTO_INCREMENT PRIMARY KEY,\n\t\t\t\t\t\t\t\t`data` TINYINT(1) UNSIGNED\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\tENGINE=" . NQ_MYSQL_TABLE_ENGINE;
        mysqli_sub_query($storage_dblink, $create_query);
        # Getting our free server space
        $query = "\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_SERVERS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`environment` \t\t\tIN ('" . mysqli_escape_string($controller_dblink, $table_data['environment'] == '*' ? 'prod' : $table_data['environment']) . "','*') AND\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\t`host_app_id` \t\tIN (" . (int) $app_data['id'] . ",0) OR\n\t\t\t\t\t\t\t`host_app_group` \tIN (" . (int) $app_data['group'] . ",0)\n\t\t\t\t\t\t)\n\t\t\t\t\tORDER BY\n\t\t\t\t\t\t`environment` DESC,\n\t\t\t\t\t\t`host_app_id` DESC,\n\t\t\t\t\t\t`host_app_group` DESC,\n\t\t\t\t\t\t`available_space` DESC\n\t\t\t\t\tLIMIT 1";
        $server_data = mysqli_single_result_query($controller_dblink, $query);
        # Temp create table hold
        $query = "SHOW CREATE TABLE " . NQ_DATABASE_STORAGE_DATABASE . ".`" . NQ_DATABASE_STRUCTURE_PREFIX . $app_data['id'] . '_' . $partition_data['table_id'] . "`";
        $create_result = mysqli_single_result_query($storage_dblink, $query);
        # Creating the new create syntax
        $partition_table_name = $app_data['id'] . '_' . $partition_data['table_id'] . '_' . $partition_data['id'];
        $syntax = explode('`', $create_result['Create Table']);
        $syntax[0] = "CREATE TABLE IF NOT EXISTS ";
        $syntax[1] = $server_data['database'] . '`.`' . $partition_table_name;
        $syntax = implode('`', $syntax);
        # Update the partition data
        $query = "\tUPDATE\n\t\t\t\t\t\t" . NQ_TABLE_PARTITIONS_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`host_id`\t=" . (int) $server_data['id'] . ",\n\t\t\t\t\t\t`table_name`\t='" . mysqli_escape_string($controller_dblink, $partition_table_name) . "'\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`\t\t=" . $partition_data['id'] . "\n\t\t\t\t\tLIMIT 1";
        mysqli_sub_query($controller_dblink, $query);
        $partition_data['host_id'] = $server_data['id'];
        $partition_data['table_name'] = $partition_table_name;
        # Open up a new connection
        $partition_dblink = mysqli_shared_connect($server_data['host'], $server_data['username'], $server_data['password'], $dbstack);
        $partition_database = $server_data['database'];
        # Creating our table
        mysqli_sub_query($partition_dblink, $syntax);
    } else {
        # Getting our free server space
        $query = "\tSELECT\n\t\t\t\t\t\t*\n\t\t\t\t\tFROM\n\t\t\t\t\t\t" . NQ_SERVERS_TABLE . "\n\t\t\t\t\tWHERE\n\t\t\t\t\t\t`id`=" . (int) $partition_data['host_id'] . "\n\t\t\t\t\tLIMIT 1";
        $server_data = mysqli_single_result_query($controller_dblink, $query);
        # Open up a new connection
        $partition_dblink = mysqli_shared_connect($server_data['host'], $server_data['username'], $server_data['password'], $dbstack);
        $partition_database = $server_data['database'];
    }
    # Returning the partition data
    $partition = (object) ['data' => $partition_data, 'database' => $partition_database, 'dblink' => $partition_dblink];
    $partition_stack[] = $partition;
    return $partition;
}
开发者ID:nuQuery,项目名称:v1m0-api-database,代码行数:63,代码来源:functions.php

示例7: track_endpoint

function track_endpoint(&$dblinks, $app_id, $environment, $endpoint)
{
    # If we want to track our usage
    if (NQ_TRACKING_ENABLED) {
        # Connecting to our tracking database
        $dblink = mysqli_shared_connect(NQ_TRACKING_HOST, NQ_TRACKING_USERNAME, NQ_TRACKING_PASSWORD, $dblinks);
        # Logging our usage
        $query = "\tINSERT INTO\n\t\t\t\t\t\t" . NQ_TRACKING_TABLE . "\n\t\t\t\t\tSET\n\t\t\t\t\t\t`app_id`\t=" . (int) $app_id . ",\n\t\t\t\t\t\t`environment`\t='" . mysqli_escape_string($dblink, $environment) . "',\n\t\t\t\t\t\t`endpoint`\t='" . mysqli_escape_string($dblink, $endpoint) . "',\n\t\t\t\t\t\t`receive_size`\t=" . (defined('NQ_RECEIVE_SIZE') ? NQ_RECEIVE_SIZE : strlen($_SERVER['QUERY_STRING'])) . ",\n\t\t\t\t\t\t`send_size`\t=" . (defined('NQ_SEND_SIZE') ? NQ_SEND_SIZE : 0) . ",\n\t\t\t\t\t\t`send_time`\t=" . ((defined('NQ_SEND_TIME') ? NQ_SEND_TIME : microtime(true)) - NQ_TRACKING_START_TIME) . ",\n\t\t\t\t\t\t`complete_time`\t=" . (microtime(true) - NQ_TRACKING_START_TIME) . ",\n\t\t\t\t\t\t`created`\t=NOW()";
        mysqli_sub_query($dblink, $query);
    }
    # Logging our endpoint
    log_access($endpoint, true);
}
开发者ID:nuQuery,项目名称:v1m0-api-authentication,代码行数:13,代码来源:functions.common.php


注:本文中的mysqli_sub_query函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。