Firstly, PostgreSQL does not have AutoCommit mode, and the pg_ * PHP API functions do not try to mimic it.
pg_query doc says
When multiple statements are passed to functions, they are automatically executed as a single transaction, unless there are explicit BEGIN / COMMIT commands included in the query string
Thus, it guarantees that pg_query("UPDATE1 ..; UPDATE2...") is executed in one transaction and renders all or nothing on the data.
Sequence
pg_query("BEGIN"); pg_query("UPDATE1..."); pg_query("UPDATE2.."); pg_query("COMMIT");
equivalent to pg_query("UPDATE1 ..; UPDATE2...") with respect to data integrity (unreachable state cannot be executed).
As for the note βif there are no explicit BEGIN / COMMIT ...β, this only matters if they are not at the beginning and end of the entire chain of SQL statements. That is, pg_query("BEGIN; update1; update2; COMMIT;"); equivalent to pg_query("update1; update2;") , but (obviously) not equivalent to pg_query("update1; COMMIT; update2;")
source share