diff --git a/lib/doh/mysql/handle.rb b/lib/doh/mysql/handle.rb
index <HASH>..<HASH> 100644
--- a/lib/doh/mysql/handle.rb
+++ b/lib/doh/mysql/handle.rb
@@ -152,8 +152,8 @@ class Handle
   end
 
   def transaction
-    need_rollback = true
     query("BEGIN")
+    need_rollback = true
     begin
       retval = yield
       query("COMMIT")
only set need_rollback to true once BEGIN has been executed