MySQL: did anyone start a transaction?

MySQL: did anyone start a transaction?

am 09.05.2009 00:23:10 von Bogdan Stancescu

Hello all,

I asked this question on php-general last month
(http://marc.info/?t=124049230300004&r=1&w=2), and received some answers
-- but I was directed to this list, so here.

My question is: can I tell programatically whether the next query I'm
going to execute is already part of a transaction, using MySQL?

The context is thus: I'm writing a PHP library which attempts to
seamlessly merge database objects and PHP objects. Architecture
discussion aside (which I'm more than open to, if anyone cares enough to
talk), I need to know whether the code outside the library has already
started a transaction or not. I need to know that because I need to
execute both PHP and SQL from a single external call -- if either one of
my internal PHP or SQL calls fail, I need to revert to the original
state before the external call. And since transactions can't be nested,
I can't unconditionally start a new transaction when the external call
is being initiated -- therefore I need to know whether the programmer
has already started a transaction or not.

Thank you,
Bogdan

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: MySQL: did anyone start a transaction?

am 11.05.2009 19:36:15 von Phpster

--001636c5acf8467cfa0469a66a64
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On Fri, May 8, 2009 at 6:23 PM, Bogdan Stancescu wrote:

> Hello all,
>
> I asked this question on php-general last month
> (http://marc.info/?t=124049230300004&r=1&w=2), and received some answers
> -- but I was directed to this list, so here.
>
> My question is: can I tell programatically whether the next query I'm
> going to execute is already part of a transaction, using MySQL?
>
> The context is thus: I'm writing a PHP library which attempts to
> seamlessly merge database objects and PHP objects. Architecture
> discussion aside (which I'm more than open to, if anyone cares enough to
> talk), I need to know whether the code outside the library has already
> started a transaction or not. I need to know that because I need to
> execute both PHP and SQL from a single external call -- if either one of
> my internal PHP or SQL calls fail, I need to revert to the original
> state before the external call. And since transactions can't be nested,
> I can't unconditionally start a new transaction when the external call
> is being initiated -- therefore I need to know whether the programmer
> has already started a transaction or not.
>
> Thank you,
> Bogdan
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

What about creating a global variable or singleton class to hold the start
of the transaction? This is something worth reading, as it indicates that
the application should manage it (
http://stackoverflow.com/questions/319788/how-do-detect-that -transaction-has-already-been-started)
and that transaction fall outside of OO scope.
--

Bastien

Cat, the other other white meat

--001636c5acf8467cfa0469a66a64--