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(); 3 13111
On 24 Apr, 12:24, FeelLikeA...@gm ail.com wrote:
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();
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?
C.
On Apr 24, 8:09 am, "C. (http://symcbean.blogsp ot.com/)"
<colin.mckin... @gmail.comwrote :
On 24 Apr, 12:24, FeelLikeA...@gm ail.com wrote:
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();
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?
C.
Yup, closing the cursor was the trick. Thanks.
About checking the return value of commits... can I configure the PDO
instance to throw an exception if the operation failed rather than
checking return values?
On Thu, 24 Apr 2008 21:17:43 +0200, <Fe**********@g mail.comwrote:
On Apr 24, 8:09 am, "C. (http://symcbean.blogsp ot.com/)"
<colin.mckin... @gmail.comwrote :
>On 24 Apr, 12:24, FeelLikeA...@gm ail.com wrote:
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();
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?
C.
Yup, closing the cursor was the trick. Thanks.
About checking the return value of commits... can I configure the PDO
instance to throw an exception if the operation failed rather than
checking return values?
Probably, I'm not sure how to make a commit fail save for not starting a
transaction, that works though:
<?php
$db = new PDO('mysql:host =localhost;dbna me=test','***** *','******');
//the magic:
$db->setAttribute(P DO::ATTR_ERRMOD E,PDO::ERRMODE_ EXCEPTION);
//test:
$db->commit();
?>
Results in:
PDOException: There is no active transaction in ....
--
Rik Wasmus This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: faktujaa |
last post by:
Hi,
I receive the above error in my code when in debug mode but im not using
serviced components instead im making use of sql server transaction. In
short, I have defined a transaction class that is derived from connection
class. In the constructor, i open a connection if one not already present and
then start the transaction by using BeginTransaction method of connection
object. In the destructor, i have called the Dispose method that...
|
by: Eitan |
last post by:
Hello,
I am using transaction in aspx code
Set myCon = Server.CreateObject("ADODB.Connection")
myCon .Open = GetConString()
.....
|
by: Vencz Istv?n |
last post by:
I have a web application installed on Windows 2003 Standard Edition
with SP1, it accesses a SQL Servet 2000 database installed on Windows
2000 Server, the two computers are not in the same domain. The web
application uses ASP pages and COM+ components written in VB6.
After the installation of SP1 for Windows 2003 the application does
not work anymore (before the installation of SP1 it worked without
problems). The following error occurs:...
|
by: cyberco |
last post by:
Using fileinput.input('test.txt') I probably forgot to process all
lines or so, since I get the error 'input() already active' when i try
to call fileinput.input('test.txt') again. But how can I 'close' the
previous version I opened? I have no handle to it or so...
|
by: johnlim20088 |
last post by:
Hi SOMEONE PLEASE HELP ME
I have a vb net program to call localhost http://localhost/hi.aspx,
my page work FINE when I browse it, but
when I call it through vb net program
it return error
The remote server returned an error: (401) Unauthorized.
| |
by: wizard |
last post by:
Hello dear friends,
I am writing a small program to test transactions in php. But when I
try to simulate an error condition during transaction, my php script
aborts. It does
rollback work, but I cannot continue the script. Please help. I am a
newbie to both php and postgresql.
PostgreSQL 7.4.17
PHP 5.1.6
|
by: bill |
last post by:
I have been "Googling" for about an hour and am turning up squat! I just
started receiving this error when trying to log into a MS Access database
from a vb .net web application. Recycling IIS seems to temporarily fix the
problem, but I am at a loss on how to view the total # of "active" sessions,
etc... any ideas or suggestions would be greatly appreciated!
Could not start session. Too many sessions already active.
Description: An...
|
by: Jialiang Ge [MSFT] |
last post by:
Hello Peter,
I once came across the same error "ExecuteReader requires the command to
have a transaction when the connection assigned? with running two threads
talking with the database. There was no problem if I use single thread or
two separate processes. These two threads are using the same connection
string, but with different connection instances. Peter, when you get the
error message, would you please check the thread list of the...
|
by: ramprat |
last post by:
I have an Access database (Access 2003). I am running Windows 2000. Until recently I have been able to run VBA code within this database on my machine but lately when I try it I get the Run time error 429 Active X Component can't create object error when the code reaches the following line
Set db = DBEngine(0)(0)
This is part of the code below.
Dim db As Database
Dim rs As Recordset
Set db = DBEngine(0)(0)
Set rs =...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |