Subject Re: [firebird-support] Uncaught exception 'PDOException' with message 'There is already an active transaction
Author Mark Rotteveel
On Thu, 31 Jan 2013 06:50:25 -0800 (PST), Nenhum Pois é
<nenhumpois@...> wrote:
> Hello world,
> I make this sample code:
> <?php
> $base_dados = blabla.fdb";
> $chave = "very_confidencial";
> $utilizador = "PHPUSER";
> $conexao = new PDO('firebird:host=localhost;dbname=' . $base_dados,
> $utilizador, $chave, array(
> ));
> $conexao->exec("SET CHARACTER SET utf8");
> $conexao->beginTransaction(); //line 11
> ?>
> When executing returns:
> PHP Fatal error: Uncaught exception 'PDOException' with message 'There
> already an active transaction' in lixo.php:11
> Stack trace:
> #0 lixo.php(11): PDO->beginTransaction()
> #1 {main}
>   thrown in lixo.php on line 11
> I am using PHP 5.4.11.
> How to implement transactions using the php PDO driver for Firebird?
> Can anyone help me? Thank you.

Why did you post it four times? Anyway, I don't use PDO or Firebird, so I
might be wrong

First of all the line:
$conexao->exec("SET CHARACTER SET utf8");

This doesn't make sense as "SET CHARACTER SET utf8" isn't supported by
Firebird (you probably need to specify the connection characterset in the
connection string, not sure how that is done for this driver). Firebird
can't execute statements without a transaction, so most likely the driver
implicitly started a transaction when you executed that first line, when
you then reach $conexao->beginTransaction(); it throws the error because it
already has an active transaction (this could also imply that the driver
doesn't implement an autoCommit).

So you either need to call beginTransaction() before any executed
statement, or check if there already is an active transaction before
starting a new one, or maybe don't need to call beginTransaction() at all
(but probably someone more familiar with PDO can give a better answer to