Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I would suggest:</p> <ol> <li><p>Using <code>InnoDB</code>, which supports row-level locking:</p> <pre class="lang-sql prettyprint-override"><code>ALTER TABLE `table` ENGINE=InnoDB; </code></pre></li> <li><p>Using a value of <code>Status</code> to indicate "in progress"; to be a little more explicit, let's use MySQL's <code>ENUM</code> type:</p> <pre class="lang-sql prettyprint-override"><code>ALTER TABLE `table` ADD status_new ENUM('queued','in progress','complete') AFTER status; UPDATE `table` SET status_new = CASE status WHEN 0 THEN 'queued' WHEN 1 THEN 'complete' END; ALTER TABLE `table` DROP status; </code></pre></li> <li><p>Using transactions within the client:</p> <pre class="lang-php prettyprint-override"><code>$dbh-&gt;setAttribute(PDO::ATTR_AUTOCOMMIT, FALSE); // pdo $mysqli-&gt;autocommit(FALSE); // mysqli (OOP) mysqli_autocommit($link, FALSE); // mysqli (procedural) mysql_query('START TRANSACTION'); // ext/mysql * </code></pre></li> <li><p>Using a <a href="http://dev.mysql.com/doc/en/innodb-locking-reads.html" rel="nofollow">locking read</a> to fetch a row to be processed:</p> <pre class="lang-sql prettyprint-override"><code>SELECT * FROM `table` WHERE status_new = 'queued' LIMIT 1 FOR UPDATE; </code></pre></li> <li><p>Setting the <code>status</code> of the fetched row to <code>'in progress'</code>:</p> <pre class="lang-sql prettyprint-override"><code>UPDATE `table` SET status_new = 'in progress' WHERE ID = ? </code></pre></li> <li><p>Committing the transaction:</p> <pre class="lang-php prettyprint-override"><code>$dbh-&gt;commit(); // pdo $mysqli-&gt;commit(); // mysqli (OOP) mysqli_commit($link); // mysqli (procedural) mysql_query('COMMIT'); // ext/mysql * </code></pre></li> <li><p>When processing is complete, <code>UPDATE</code> the record again to mark it as such.</p></li> </ol> <p>Beware that you correctly detect and handle any errors that arise at each stage.</p> <p>* note that <code>ext/mysql</code> has not been recommended for use in new code since June 2011 and is now deprecated in PHP v5.5.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload