I've dealt with a similar problem once...
The key to the solution is that the $sth->rows method will return the number of rows affected by the last query-like statement. SELECT *and* UPDATE are query-like statements, so here it goes...
You have to create a control field in the table with an int value and set it's default value to some non-null value.
Then you do the following...
-- fetch 10 to avoid querying too many times.... SELECT * FROM tablex ORDER BY dateofinsertion LIMIT 10; -- Mark the register as owned by you UPDATE tablex SET controlfield=controlfield+1 WHERE id=$id AND control +field=$controlfieldvalue;
When you execute the second query, you test the rows.
if ($sth->rows) { # it did the update, so the row is mine. } else { # someone else took the register, let's try another one }
Simple, isn't it? If some process fail, next time a process get the 10 registers, it will get that again and try to process.
In reply to Re: Database queue logic
by ruoso
in thread Database queue logic
by Marcello
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |