Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7643083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:21:25+00:00 2026-05-31T09:21:25+00:00

I use pg_connect, and pg_query in a project. But I’m really not sure that

  • 0

I use pg_connect, and pg_query in a project.
But I’m really not sure that is pg_connect using AutoCommit mode or not?

It is important question, because I need to write some block under transaction, and if one of the statements would be ignored by the server, the database would be inconsistent…

Also interesting question that do pg_query a commit after execution?

For example:

pg_query('begin; update table1...; update table2...; commit');

is same as

pg_query('begin;');
pg_query('update table1...;');
pg_query('update table2...;');
pg_query('commit');

and is the

pg_query('begin; update table1...; update table2...; commit');

working in AutoCommit mode, so begin and commit is nevertheless?

Thanks for your help:
dd

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:21:27+00:00Added an answer on May 31, 2026 at 9:21 am

    First, there is no AutoCommit mode in PostgreSQL and the pg_* functions of the PHP API do not try to emulate one.

    pg_query’s doc says

    When multiple statements are passed to the function, they are
    automatically executed as one transaction, unless there are explicit
    BEGIN/COMMIT commands included in the query string

    So it guarantees that pg_query("UPDATE1 ..; UPDATE2...") executes in one transaction and has an all-or-nothing effect on the data.

    The sequence

    pg_query("BEGIN");
    pg_query("UPDATE1...");
    pg_query("UPDATE2..");
    pg_query("COMMIT");
    

    is equivalent to pg_query("UPDATE1 ..; UPDATE2...") with regard to data integrity (half-finished state cannot happen).

    As for the note “unless there are explicit BEGIN/COMMIT…”, it is relevant only if these are not at the beginning and end of the entire chain of SQL statements.
    That is, pg_query("BEGIN; update1; update2; COMMIT;"); is equivalent to pg_query("update1; update2;") but (obviously) not equivalent to pg_query("update1; COMMIT; update2;")

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a Microsoft Access database for a demo project that I'm
use this website a lot but first time posting. My program creates a number
Use case: I've just entered insert mode, and typed some text. Now I want
We use a data acquisition card to take readings from a device that increases
It is know that connection to the SQL server will not be closed when
I'm experiencing some behavior I did not expect. I have a synchronous procedure that
I want to use sqlite3 but pg for production on heroku. However, I don't
i have a LAPP (linux, apache, postgresql and php) environment, but the question is
I want to use PostgreSQL in the client side. is that possible? can i
I can use pg_get_pid when pgsql connected by pg_connect : $conn = pg_pconnect(host=localhost port=5432

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.