繁体   English   中英

如何维护多个打开的查询?

[英]How can I maintain multiple open queries?

我有一些需要使用SQL的php文件。 在该SQL中,我得到多个结果,在这里使用while($stmt->fetch()){}循环,在其中需要使用另一个SQL。 这可以完成吗,还是我需要存储第一个SQL查询的结果,关闭它之后,我可以打开新的SQL查询。

这是代码:

function compute_production($local_id, $GameID) {
    global $mysqli, $M, $Q;
    $sql = "SELECT `x`, `y`, `building`, `tier` FROM `GOD_battlefields` WHERE `owner`=? AND `game_id`=?";
    $stmt = $mysqli->prepare($sql);                                      
    $stmt->bind_param("ii", $local_id, $GameID);
    $stmt->execute();
    $stmt->bind_result($x, $y, $BUILDING, $TIER);
    while($stmt->fetch()) {

        $AB_triggered = array();

        fOReaCh(tech_get_value($BUILDING, "abilities") as $ability_name => $required_tier) {
            if ($TIER >= $required_tier) {


                switch($ability_name) {
                    case "auto_production":
                    $AB_triggered[$ability_name] = "true";
                        break;
                    case "toggle_production":
                    case "double_production":
                        // check if the order is clicked

                        $sql = "SELECT `post_value` FROM `GOD_cache` WHERE `post_name`=? AND `post_value` LIKE ? AND `game_id`=? AND `round`=?";
                        $AB_triggered[$ability_name] = "false";
                        $post_name = 'AbilityOrder_'.$x.'_'.$y;
                        $stmt2 = $mysqli->prepare($sql);                                      
                        $stmt2->bind_param("ssii", $post_name, $ability_name, $GameID, $Q->game_round);
                        $stmt2->execute();
                        $stmt2->bind_result($AbilityOrder);
                        if ($stmt2->fetch()) {
                            $stmt2->close();

                            $AB_triggered[$ability_name] = "true";
                        } else {
                            // Keep calm and do nothing
                            // Everything is fine
                            // No action needed
                            // Really


                        }
                        break;
                }
            }
        }



        foreach(tech_get_value($BUILDING, "production") as $r => $value) {
            if ($r == "s" || $r == "io" || $r == "w") {
                // check if cell contains those resources 
                $multiplier = ($Q->resources_in_cell($x, $y)[$r] > $value ? 1 : 0.15);
                $value *= $multiplier; // Multiply gained resources --> if mines/forests/quarries are empty, gained resources are decreased
            }
            $value *= tech_get_value($BUILDING, "productionm", $r) ** ($TIER - 1);
            if ($AB_triggered["toggle_production"] == "true" || $AB_triggered["auto_production"] == "true") {
                $RES_PER_TURN[$r] += $value;
            }
        }
        // information about production costs
        $HTML_battlefield .= "for the cost of: <br />";
        foreach(resources_for_production_gen($x, $y, array($BUILDING, $TIER)) as $resource => $cost) {
            if ($AB_triggered["toggle_production"] == "true" || $AB_triggered["auto_production"] == "true") {
                $RES_PER_TURN[array_search($resource, $dictionary_resource)] -= $cost;
            }
        }

    }

    return $RES_PER_TURN;
}

不断在$stmt2->bind_param();上抛出错误$stmt2->bind_param();

答案是:没有办法,如何维护多个打开的查询。

解决方案可能是使用某些INNER JOIN或其他JOIN或存储来自第一个SQL的信息,关闭SQL,然后打开下一个SQL并使用存储的信息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM