如何从PHP multiquery语句获取第二个结果集?

时间:2013-10-24 14:10:41

标签: php mysqli-multi-query

我想从这个multiquery语句中的第二个查询中获得结果。目前,我构建它的方式是从两个查询语句中得到结果:

$query = ("call calcfields2_new('$_SESSION[Userid]');");
$query .= "SELECT * FROM CalcFields WHERE Userid=$_SESSION[Userid]"; 

if (mysqli_multi_query($dbc, $query)) {
do {
    if ($result = mysqli_store_result($dbc)) {
        while ($row = mysqli_fetch_assoc($result)) {

    $array1[]=$row;
        }
        mysqli_free_result($result);
        }
    if (mysqli_more_results($dbc)) {
    }
} 
while (mysqli_next_result($dbc));
}
}

echo(json_encode($array1));     

1 个答案:

答案 0 :(得分:0)

这样做是为了吗?

$query = ("call calcfields2_new('$_SESSION[Userid]');");
$query .= "SELECT * FROM CalcFields WHERE Userid=$_SESSION[Userid]";

preg_match_all("/(?:(.*?)\s.*?(?:;|$))/",$query,$first_word);

if(mysqli_multi_query($dbc,$query)){
    do{
        if($result=mysqli_store_result($dbc)){
            if(array_shift($first_word[1])=="SELECT"){
                while($row=mysqli_fetch_assoc($result)) {
                    $array1[]=$row;
                }
            }
            mysqli_free_result($result);
        }
    } while(mysqli_more_results($dbc) && mysqli_next_result($dbc));
}
// if($error_mess=mysqli_error($dbc)){echo "Error: $error_mess";}

echo(json_encode($array1));