Search code examples
phptransactionsdelaylamp

I would like to synchronize the php execution to the mysql transaction. (Cause php to wait until the transaction is complete.... )


$query = "START TRANSACTION;\n".$update.$insert."COMMIT;\n";

//print $query;

if (!$mysqli->multi_query($query)) {
    echo "Multi query failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

// need to delay somehow until after the transaction is complete.

header('Location: ../seller-services.php?services=$'.$services);

The problem I am having is when I call the seller-services.php the changes just made by the transaction are not reflected in the database yet, so the queries I use to generate the output for seller-services.php aren't necessarily visible. If I hit refresh I will see the changes. I could do some type of hard delay, like a second, but I would rather synchronize the php execution to the mysql transaction. If that is possible please let me know.

I don't think the type of query is important but in case you would like to see part of this query in more concrete form:

Inside a loop I:

        $insert .= "
INSERT INTO SellerServices
  (`id`, `Type`, `Details`, `Active`)
VALUES
  ('$id', '$type', '$details', '1')
ON DUPLICATE KEY UPDATE
  `Details`='$details',
  `Active`='1';\n";
  $services .= "&$type";

I think you can use your imagination for the rest


Solution

  • You just need to loop through each query, even if you don't do anything:

    while ($mysqli->next_result()) {}