Keith Watanabe * NET 2.0

Wrappig a postgresql transaction
By: Keith Watanabe
Published On: 2-29-2004

Some code for wrapping a postgresql transaction: pg_exec($conn, "begin work"); $res = pg_exec($conn, $sql); if (!$res) { $err = pg_errormessage($conn); pg_exec($conn, rollback"); return 0; } else { pg_exec($conn, "commit"); return 1; } I'm assuming that this wrapper code is inside of a function (hence the return). I prefer placing this code in a reusable object which allows me to handle transactions better and so that other objects can extend this base class. It also makes maintaining the connection string easier since you can set it in the base constructor class and not worry too much about setting it later. I've simplified this although if you want your application to be smart, you can't do this in such a generic manner.

Tags: php
AddThis Social Bookmark Button Sphere: Related Content

Trackbacks: (Trackback URL)

No Comments Posted Yet
October [November] December
Sun Mon Tue Wed Thu Fri Sat
26 27 28 29 30 31 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 1 2 3 4 5 6