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.
Trackbacks: (Trackback URL)