php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #34719 Add proposal about the pg_query function documentation
Submitted: 2005-10-03 17:08 UTC Modified: 2005-10-14 10:22 UTC
From: bouchon at alussinan dot org Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: bouchon at alussinan dot org
New email:
PHP Version: OS:

 

 [2005-10-03 17:08 UTC] bouchon at alussinan dot org
Description:
------------
Hello,

I would like to propose to add a short explanation inside the documentation of the pg_query function, about transactions :

##

Note that the pg_query() function can also take several queries embeded inside one transaction block.

Example :

$SQLQuery = 'BEGIN;';
$SQLQuery.= 'INSERT INTO a (a,b) VALUES (1,2);';
$SQLQuery.= 'INSERT INTO b (ref_b,c) VALUES (2,5);';
$SQLQuery.= 'COMMIT;';

$HandleResults = pg_query($SQLQuery);


The essential point of a transaction is that it bundles multiple steps into a single, all-or-nothing operation. You can get more informations about transaction on http://www.postgresql.org/docs/8.0/interactive/tutorial-transactions.html
##

I think that this feature should be mentionned inside the pg_query() function documentation. If this proposal is accepted, feel free to rewrite it in a better english.

Kind regards,

-- 
Bruno BAGUETTE - bouchon@alussinan.org
(hardly filtered mail, but I read answers on the newsgroup) 


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-03 18:31 UTC] kouber@php.net
Actually, pg_query() automatically encloses everything in a transaction block, unless a transaction has already been started - in which case the queries again fit into one transaction.

However, you're right - it would be good to mention that multiple queries could be passed to pg_query() and they all are executed as one transaction.

 [2005-10-03 19:23 UTC] kouber@php.net
Take a look at

http://www.postgresql.org/docs/8.0/interactive/libpq-exec.html

"It is allowed to include multiple SQL commands (separated by semicolons) in the command string. Multiple queries sent in a single PQexec call are processed in a single transaction, unless there are explicit BEGIN/COMMIT commands included in the query string to divide it into multiple transactions. Note however that the returned PGresult structure describes only the result of the last command executed from the string. Should one of the commands fail, processing of the string stops with it and the returned PGresult describes the error condition."

That means, that if you have explicitly multiple transactions in one pg_query() invocation, if one of them fails, the execution of the following commands will also fail. So, generally, it's not a good idea to use multiple transactions in one pg_query call.

Btw, in the PHP documentation it's described well enough, that pg_query() accepts "statement or statements".
 [2005-10-03 23:27 UTC] bouchon at alussinan dot org
Hello,

You are right, the documentation indicates "statement or statements", but I think that is too discreet (I didn't saw the mention).

Maybe complete that sentence like this : "The SQL statement or statements (SQL transaction) to be executed."

And/or add a second example "Example 2. pg_query() example using SQL transaction".

$SQLQuery = 'BEGIN;';
$SQLQuery.= 'INSERT INTO a (a,b) VALUES (1,2);';
$SQLQuery.= 'INSERT INTO b (ref_b,c) VALUES (2,5);';
$SQLQuery.= 'COMMIT;';

$HandleResults = pg_query($SQLQuery);

if (!$HandleResults) {
  echo "An error occured.\n";
  exit;
}

Imho (but it is just my humble opinion), even if that feature is mentionned, it should be more in evidence.

Best Regards,
 [2005-10-04 14:57 UTC] kouber@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 [2005-10-14 10:22 UTC] bouchon at alussinan dot org
Hello,

I just saw the changes appears in my PHP doc mirror. This is just perfect in my humble opinion !

So, I move the status of that ticket to 'Closed'.

Thanks for your helpfull job ! :-)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 10 12:01:33 2025 UTC