Re: [PHP-PEAR] possible bug in DB/pgsql.php
| Newsgroups | php.pear |
|---|---|
| Message-ID | <3A882984.7089.205E132@localhost> |
On 12 Feb 2001, at 18:43, Burak DAYIOGLU wrote:
> The below code is assumed to make two inserts and rollback afterwards.
> I was expecting to see no records inserted however both inserts ended
> with success.
>
In reality, $database->autocommit(FALSE) should have raised an
error, since it's not supported in the PGSQL port (at least in my
version)...
> Any ideas on how to implement transactions with postgresql? Am I doing
> anything wrong? (BTW, running on RH6.2 Linux w/ Php4.0.4pl1, cvs
> synched fresh PEAR and pgsql 7.0.3...)
>
Considering PG API, I think the most straightforward way is to add
a "start transaction" method, simmetric to $db->commit() and
$db->rollback - say, something like $db->begin().
It could be done by hacking DB/pgsql or by subclassing it. Being
from PHPlib background, I'd suggest the latter :-)
The code for that method should be quite simple:
function begin() {
$result = pg_exec($this->connection, "begin;");
if (!$result) {
return pg_errormessage($this->connection);
}
return DB_OK;
}
Implementing this using the $db->autocommit() flag would be a lot
more painful, IMVHO.
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
Fabrizio Ermini Alternate E-mail:
C.so Umberto, 7 [email protected]
loc. Meleto Valdarno Mail on GSM: (keep it short!)
52020 Cavriglia (AR) [email protected]