Re: Cleaning up aborted transactions

Поиск
Список
Период
Сортировка
От Adrian Tineo
Тема Re: Cleaning up aborted transactions
Дата
Msg-id 000801c32f27$553013b0$926bd9d9@clairvo
обсуждение исходный текст
Ответ на Cleaning up aborted transactions  (Michael Glaesemann <grzm@myrealbox.com>)
Ответы Re: Cleaning up aborted transactions  (Michael Glaesemann <grzm@myrealbox.com>)
Список pgsql-php
The correct way of working with transactions is to use:

BEGIN
...sql commands
COMMIT or ROLLBACK

So I would use this for example:

pg_connect($connection);
pg_query($connection,"BEGIN;");
$insert="INSERT INTO table VALUES (2,7,5);
$result=pg_query($connection,$insert);
if(!$result){
    pg_query($connection,"ROLLBACK");
    //Something went wrong with the insert so we rollback and nothing
changes in the db
}else{
    pg_query($connection,"COMMIT");
    // If everything went all right, then we commit the changes
}
pg_close($connection);

Of course, the interesting thing comes when you have several operations
(inserts, deletes or updates) between begin and commit, this way either you
make all the changes or make none, that's the cool thing about transactions.
In each operation just check whether the result was valid or not. If ANY of
them was invalid, rollback and none of the changes will take effect.

I don't know if this answer your question...

Adrian Tineo



В списке pgsql-php по дате отправления:

Предыдущее
От: Michael Glaesemann
Дата:
Сообщение: Cleaning up aborted transactions
Следующее
От: Michael Glaesemann
Дата:
Сообщение: Re: Cleaning up aborted transactions