What is the problem you're having?
I can see a couple of things.
One, all of the operations should be done in a single transaction so that if any of them fail the tables aren't in an inconsistent state.
Two, the selection and insertion can be done in a single statement (INSERT ... SELECT...
) except for the TimeProcessed
column, which, since it's just an integer, could perhaps be interpolated or otherwise use the database's time functions.
Three is how you're selecting the "top" item in the queue, which is apparently the one where No=1
. How are you determining which row should have No=1
? Once you've removed No=1
what happens when there is no longer a row with No=1
? If this is a queue, wouldn't the next record to process just be the one with the earliest TimeIssued
value? Or were you planning to UPDATE
every record in the table every time you processed one row?
Oh, another thing:
$result = $conn->query($sql);
if ($conn->query($sql) === TRUE) {
You run the query and collect the result, and then you immediately run the same query again and this time try to compare it to a boolean — instead of just seeing if $result
is a valid result, or if the connection's errno
is zero.