Recent Posts
None | 1 sec ago
None | 35 sec ago
None | 44 sec ago
Java | 1 min ago
None | 1 min ago
Python | 2 min ago
Python | 2 min ago
HTML | 2 min ago
mIRC | 2 min ago
None | 2 min ago
Sitereport
Find cool info about any domain on the internet?
visit sitereport
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By zingbats on the 10th of Feb 2010 12:25:02 AM Download | Raw | Embed | Report
  1. <?php
  2. query("START TRANSACTION");
  3. //
  4. // Check there are enough bottles of wine left in the `items` table
  5. //
  6. $bottles_left = query("SELECT `number` FROM `items` WHERE `type` = 'wine' LIMIT 1 FOR UPDATE;");
  7. //
  8. // If we have bottles left
  9. //
  10. if( $bottles_left > 0) {
  11.         //
  12.         // Call a function that returns TRUE on WIN
  13.         // This simulates a competition
  14.         //
  15.         $did_we_win = generate_win();
  16.         if( $did_we_win ) {
  17.                 //
  18.                 // Rollback at the first sign of error
  19.                 //
  20.                 query("UPDATE `users` SET `prizes_won`= prizes_won+1 WHERE `user_id` = $UID") or query("ROLLBACK");
  21.                
  22.                 query("UPDATE `items` SET `number` = number-1 WHERE `type` = 'wine' LIMIT `;") or query("ROLLBACK");
  23.                 //
  24.                 // We have done everything, so we commit
  25.                 //
  26.                 query("COMMIT");
  27.         } else {
  28.                 query("COMMIT");
  29.         }
  30. } else {
  31.         query("COMMIT");
  32. }
  33. ?>
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: