카테고리 없음

[PHP] PHP에서 mysql_multi_query를 어떻게 사용할 수 있습니까?

행복을전해요 2021. 2. 28. 18:52

공식 문서 에 따르면 두 가지 방법이 있습니다. 객체 지향 방식을 사용하지 않기 때문에 절차 적 방식의 예제 (내가 말했듯이 문서에서)를 거의 복사하여 붙여 넣을 것입니다.

// Your queries
$query="INSERT into statement(statementno) VALUES('".$statementno."')"; 
    $query.="INSERT into   
              receipt(statementno,accountnum,dateofpayment,amount,submittedby)   
                        VALUES('".$statementno."','".$accno."','".$dateofpayment."','".$amount."','".$submittedby."')";
                        
                        /* execute multi query */
                        if (mysqli_multi_query($con, $query)) {
                            do {
                                    /* store first result set */
                                            if ($result = mysqli_store_result($con)) {
                                                        while ($row = mysqli_fetch_row($result)) {
                                                                        printf("%s\n", $row[0]); // Or whatever...
                                                                                    }
                                                                                                mysqli_free_result($result); // Free in order to store the next
                                                                                                        }
                                                                                                                }
                                                                                                                    } while (mysqli_next_result($con));
                                                                                                                    }
                                                                                                                    


출처
https://stackoverflow.com/questions/22089787