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...
By zingbats on the 10th of Feb 2010 12:25:02 AM
Download |
Raw |
Embed |
Report
<?php
query("START TRANSACTION");
//
// Check there are enough bottles of wine left in the `items` table
//
$bottles_left = query("SELECT `number` FROM `items` WHERE `type` = 'wine' LIMIT 1 FOR UPDATE;");
//
// If we have bottles left
//
if( $bottles_left > 0) {
//
// Call a function that returns TRUE on WIN
// This simulates a competition
//
$did_we_win = generate_win();
if( $did_we_win ) {
//
// Rollback at the first sign of error
//
query("UPDATE `users` SET `prizes_won`= prizes_won+1 WHERE `user_id` = $UID") or query("ROLLBACK");
query("UPDATE `items` SET `number` = number-1 WHERE `type` = 'wine' LIMIT `;") or query("ROLLBACK");
//
// We have done everything, so we commit
//
query("COMMIT");
} else {
query("COMMIT");
}
} else {
query("COMMIT");
}
?>
Submit a correction or amendment below.
Make A New Post