Closing the cursor before running another query


show more Closing the cursor before running another query 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 ...

Closing the cursor before running another query

In the previous video, we created a transaction to transfer money from one account to another. But there was nothing to prevent the transaction from going ahead if the payer ran out of funds. This is pdo_check_balance.php which you can find in the Chapter 3, 03_07 folder of the exercise files. The script has been updated to roll back the transaction if the balance in the outgoing account falls below zero. Adding this extra step results in some databases displaying the wrong balance after the transaction has been rolled back.

The fix is very easy but first let's take a look at the code and see what's happening. On line nine is a new prepared statement with a named placeholder that gets the balance from the savings account for the payer. Then on lines 16 and 17 the statement is prepared and the payer's name is bound to the named placeholder. The third statement is executed a bit further down, here on line 31. And then, on line 32, the fetchColumn method is used to get the result.

There's o...

Closing the cursor before running another query
Video duration: 4m 42s 3h 47m Intermediate

Viewers:

Closing the cursor before running another query 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 ...