I have the code below. First there is a transaction where I select
data. I wrapped it in an explicit transaction because in my real
program I run a couple different selects. Nevertheless, the
transaction should be closed with the commit command.
Next, I there is a separate transaction where I update data. But I get
the error: Uncaught exception 'PDOException' with message 'There is
already an active transaction'.
I don't understand why the first transaction is still considered
active.
$dbh = new PDO('sqlite:Mov ies.sqlite');
$movieID = 1; // or whatever, just for testing
$dbh->beginTransacti on();
$selectMovie = $dbh->prepare('
SELECT movie_title
FROM movies
WHERE movie_id = :movieID
');
$selectMovie->bindParam(':mo vieID', $movieID);
$selectMovie->execute();
$movieResult = $selectMovie->fetch(PDO::FET CH_ASSOC);
$dbh->commit();
var_dump($movie Result);
$movieTitle = 'Some Other Blah Title';
$dbh->beginTransacti on();
$updateMovie = $dbh->prepare('
UPDATE movies
SET movie_title = :movieTitle
WHERE movie_id = :movieID
');
$updateMovie->bindParam(':mo vieTitle', $movieTitle);
$updateMovie->bindParam(':mo vieID', $movieID);
$updateMovie->execute();
$dbh->commit();
data. I wrapped it in an explicit transaction because in my real
program I run a couple different selects. Nevertheless, the
transaction should be closed with the commit command.
Next, I there is a separate transaction where I update data. But I get
the error: Uncaught exception 'PDOException' with message 'There is
already an active transaction'.
I don't understand why the first transaction is still considered
active.
$dbh = new PDO('sqlite:Mov ies.sqlite');
$movieID = 1; // or whatever, just for testing
$dbh->beginTransacti on();
$selectMovie = $dbh->prepare('
SELECT movie_title
FROM movies
WHERE movie_id = :movieID
');
$selectMovie->bindParam(':mo vieID', $movieID);
$selectMovie->execute();
$movieResult = $selectMovie->fetch(PDO::FET CH_ASSOC);
$dbh->commit();
var_dump($movie Result);
$movieTitle = 'Some Other Blah Title';
$dbh->beginTransacti on();
$updateMovie = $dbh->prepare('
UPDATE movies
SET movie_title = :movieTitle
WHERE movie_id = :movieID
');
$updateMovie->bindParam(':mo vieTitle', $movieTitle);
$updateMovie->bindParam(':mo vieID', $movieID);
$updateMovie->execute();
$dbh->commit();
Comment