Executing a transaction


show more Executing a transaction provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP show less
please wait ...

Executing a transaction

Transactions allow you to treat a series of SQL queries as a single unit that's executed only if all parts of it succeeds. Let's use a very simple example to see how transactions work. This is pdo_transaction.php which you can find in the Chapter 3, 03_06 folder of the exercise files. If we scroll down a little on line 27 is a loop that loops over a query that selects the name and balance values from a table called savings.

Then on lines 29 and 30 those values are displayed. So, let's just take a quick at that in a browser. It's a very small savings bank we've got here, just two accounts. One for John White, one for Jane Black. They've both got a $1,000 in their account. We'll use a transaction to transfer $200 from John's account to Jane's. So, let's go back to the editing program. And to save some time, I'm going to paste in some prepared statements to setup the transfer.

The code is in transfer.txt, which you can find in the exercise files for this video....

Executing a transaction
Video duration: 6m 54s 3h 47m Intermediate

Viewers:

Executing a transaction provides you with in-depth training on Developer. Taught by David Powers as part of the Accessing Databases with Object-Oriented PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...