0

The following code updates the table correctly, but it also returns an Exception. Any idea what might be happening here?

public function updateThis($aaa){
try
{
    $success = false;

    $query = "
        UPDATE this_table
        SET thing = '0'
        WHERE aaa = :aaa";

    $stmt = $this->conn->prepare($query);

    $stmt->bindParam(':aaa', $aaa);

    $stmt->execute();

    if($this->conn->commit())
        $success = true;

    return $success;
}
catch(Exception $e)
{
    return $e;
}
}
4
  • 1
    What does $e->getMessage() say? Commented Jul 17, 2012 at 0:06
  • @drew010 It says "drew010 is a legend, give the man a point.." Actually, it said "There is no active transaction" to which I went back and added $this->conn->beginTransaction(); it now works.. Commented Jul 17, 2012 at 0:12
  • Do I even need a transaction for this one row update? Commented Jul 17, 2012 at 0:15
  • @rideTheWave Probably not, unless is happens to be an exceptionally long single row update. Commented Jul 17, 2012 at 0:16

1 Answer 1

1

When you are using PDO, Auto-Commit is on by default, unless you specifically turn it off using Begin Transaction. I can't see it in your connection, so are you perhaps trying to commit a transaction that has already been auto-commited?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.