11.8. PHP and Transactions

Transactions and locks are strongly related to each other. After you have seen how locks can be treated, you can take a closer look at PHP and transactions. Usually working with transactions is an easy task. However, a closer look is necessary to find out what happens to uncommitted transactions. The next example shows what happens with transactions that are not committed manually:

 <?php $dbh = pg_connect("host=localhost user=postgres dbname=phpbook"); if (!$dbh) { echo "error while connecting.<br>\n"; } execute("BEGIN;"); execute("INSERT INTO plant VALUES (6, 'cactus', 'green')"); function execute($sql) { global $dbh; $status = pg_exec($dbh, $sql); if (!$status) { echo "an error has occurred when executing ($sql)<br>\n"; ...

Get PHP and PostgreSQL: Advanced Web Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.