mysqli_multi_query只执行第一个查询,似乎缺少什么?

时间:2011-06-30 03:27:16

标签: mysqli

$ userid = mysqli_real_escape_string($ link,$ _SESSION ['user'] [0]);         $ lastid = mysqli_insert_id($ link);

    mysqli_autocommit($link, FALSE);

    //make the string
    $sql = "INSERT INTO district (DistID, Dist, UserID) VALUES(NULL, '".$dist->getDist()."', '".$userid."');";
    $sql .= "INSERT INTO lok (LocID, Loc, DistID) VALUES(NULL, '".$loc->getLokal()."','".$lastid."');";
    $sql .= "INSERT INTO schedule (SchedID, Mon, LocID) 
                VALUES(NULL, '".$sched->getMon()."', '".$lastid."')";

    // execute query
    if ($result = mysqli_multi_query($link, $sql)){
        do {
            if ($result = mysqli_use_result($link)) {
             while ($row = mysqli_fetch_row($result)) {
                }
            mysqli_free_result($result);
        }
        } while (mysqli_next_result($link));

        mysqli_commit($link);

    }
    else
    {
        mysqli_rollback($link);
    }
        mysqli_close($link);

1 个答案:

答案 0 :(得分:0)

您必须使用mysqli_use_resultmysqli_store_result获取第一个查询的结果。