You're in luck; PostgreSQL makes it very easy--just issue the queries 'begin', 'commit', and/or 'rollback'. For example, assuming $conn is your database connection handle:
pg_exec($conn, 'begin');
if (pg_exec($conn,'delete from detail where id = $id')
&& pg_exec( $conn, 'delete from master where id = $id'))
pg_exec($conn, 'commit');
else
pg_exec($conn,'rollback');