ID: 34719 Updated by: [EMAIL PROTECTED] Reported By: bouchon at alussinan dot org Status: Open Bug Type: Documentation problem PHP Version: Irrelevant New Comment:
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". Previous Comments: ------------------------------------------------------------------------ [2005-10-03 18:31:15] [EMAIL PROTECTED] 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 17:08:46] 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 - [EMAIL PROTECTED] (hardly filtered mail, but I read answers on the newsgroup) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34719&edit=1
