The correct way of working with transactions is to use:
BEGIN
...sql commands
COMMIT or ROLLBACK
So I would use this for example:
pg_connect($connection);
pg_query($connection,"BEGIN;");
$insert="INSERT INTO table VALUES (2,7,5);
$result=pg_query($connection,$insert);
if(!$result){
pg_query($connection,"ROLLBACK");
//Something went wrong with the insert so we rollback and nothing
changes in the db
}else{
pg_query($connection,"COMMIT");
// If everything went all right, then we commit the changes
}
pg_close($connection);
Of course, the interesting thing comes when you have several operations
(inserts, deletes or updates) between begin and commit, this way either you
make all the changes or make none, that's the cool thing about transactions.
In each operation just check whether the result was valid or not. If ANY of
them was invalid, rollback and none of the changes will take effect.
I don't know if this answer your question...
Adrian Tineo