PDO Error: Already Active Transaction -- Help

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
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

$dbh = new PDO('sqlite:Movies.sqlite');
$movieID = 1; // or whatever, just for testing

$selectMovie = $dbh->prepare('
    SELECT movie_title
    FROM movies
    WHERE movie_id = :movieID
$selectMovie->bindParam(':movieID', $movieID);
$movieResult = $selectMovie->fetch(PDO::FETCH_ASSOC);

$movieTitle = 'Some Other Blah Title';
$updateMovie = $dbh->prepare('
    UPDATE movies
    SET movie_title = :movieTitle
    WHERE movie_id = :movieID
$updateMovie->bindParam(':movieTitle', $movieTitle);
$updateMovie->bindParam(':movieID', $movieID);

Re: PDO Error: Already Active Transaction -- Help

On 24 Apr, 12:24, FeelLikeA...@gmail.com wrote:
Quoted text here. Click to load it

You don't check if the commit was successful but more probably, its
because you haven't closed the cursor before executing the next exec.
Also why do you think you need a transaction when you're not doing any
DML/DDL updates?


Site Timeline