以下のコードを実行すると、2番目のループ(数量がループする回数)で、コマンドの同期が外れるというエラーが発生します。これは何が原因ですか?
PHPコード:
while ($i < $quantity) {
$result = mysqli_multi_query($con, "
INSERT INTO parts (capacity, length, width, height, orientation, weight, location, description, status, partNumber) VALUES ('$capacity', '$length', '$width', '$height', '$orient', '$weight', '$location', '$desc', '$status', '$partNum');
INSERT INTO craneparts (craneID, partsID) VALUES ('$craneID', LAST_INSERT_ID());
") or die(mysqli_error($con));
$i++;
}
https://dev.mysql.com/doc/refman/5.0/en/commands-out-of-sync.html
コマンドが同期しなくなった場合。クライアントコードでこのコマンドを実行することはできません。クライアント関数を間違った順序で呼び出しています。
これは、たとえば、mysql_use_result()を使用していて、mysql_free_result()を呼び出す前に新しいクエリを実行しようとした場合に発生する可能性があります。また、間にmysql_use_result()またはmysql_store_result()を呼び出さずにデータを返す2つのクエリを実行しようとした場合にも発生する可能性があります。
呼び出してみmysqli_next_resultをごmysqli_multi_queryの呼び出しの間
while ($i < $quantity) {
$result = mysqli_multi_query($con, "
INSERT INTO parts (capacity, length, width, height, orientation, weight, location, description, status, partNumber) VALUES ('$capacity', '$length', '$width', '$height', '$orient', '$weight', '$location', '$desc', '$status', '$partNum');
INSERT INTO craneparts (craneID, partsID) VALUES ('$craneID', LAST_INSERT_ID());
") or die(mysqli_error($con));
while(mysqli_more_results($con) && mysqli_next_result($con)) {;} // flush multi_queries
$i++;
}
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加