Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/lsp4you/public_html/connect.php on line 2 LSP4YOU - Learner's Support Publications

Transaction - Examples

TRANSACTION WITHDRAWAL (x, withdrawal_amount)
Begin transaction
	IF X exist then
		READ X.balance
		IF X.balance > withdrawal_amount THEN
			SUBTRACT withdrawal_amount
			WRITE X.balance
			COMMIT
		ELSE
			DISPLAY “TRANSACTION CAN NOT BE PROCESSED”
	ELSE
	DISPLAY “ACCOUNT X DOES NOT EXIST”
End transaction;

TRANSACTION TRANSFER (x, y, transfer_amount)
Begin transaction
	IF x AND y exist then
		READ x.balance
		IF x.balance > transfer_amount THEN
			x.balance = x.balance – transfer_amount
			write x.balance
			READ y.balance
			y.balance = y.balance + transfer_amount
			write y.balance
			COMMIT
		ELSE
			DISPLAY “BALANCE IN X NOT OK”
			ROLLBACK
	ELSE
	DISPLAY “ACCOUNT x OR y DOES NOT EXIST”
End transaction;