MySql Rollback

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Joined: Mar 12, 2007
  • Posts: 6228
  • Loc: South-Africa
  • Status: Offline

Post October 29th, 2009, 8:14 am

Hi, long time no see ... I have been really busy the last while, don't even have time to breathe properly.
Anyhow, I don't quite understand MySql rollbacks properly, so here is my question:

I have something like the following:

Code: [ Select ]
include_once("class.data.php");
include_once("class.something.php");
//the 'something' class extends the 'data' class.
$something = New Something();
$something->create("data");
$something->create("something");
  1. include_once("class.data.php");
  2. include_once("class.something.php");
  3. //the 'something' class extends the 'data' class.
  4. $something = New Something();
  5. $something->create("data");
  6. $something->create("something");


when running the '$something->create()' method it runs two seperate MySql queries one inserts into the 'data' table and the other into the 'something' table. These queries are automatically created by 'EXPLAIN'ing the table I pass as the paramenter.

I was then trying something as follows:


Code: [ Select ]
include_once("class.data.php");
include_once("class.something.php");
//the 'something' class extends the 'data' class.
$temp = mysql_query("START TRANSACTION");
$something = New Something();
$something->create("data");
$something->create("something");
$temp = mysql_query("ROLLBACK");
  1. include_once("class.data.php");
  2. include_once("class.something.php");
  3. //the 'something' class extends the 'data' class.
  4. $temp = mysql_query("START TRANSACTION");
  5. $something = New Something();
  6. $something->create("data");
  7. $something->create("something");
  8. $temp = mysql_query("ROLLBACK");


but it didn't do anything, both rows still inserted into the database. What exactly is the issue here?
Let's leave all our *plum* where it is and go live in the jungle ...
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 29th, 2009, 8:14 am

  • joebert
  • Sledgehammer
  • Genius
  • No Avatar
  • Joined: Feb 10, 2004
  • Posts: 13455
  • Loc: Florida
  • Status: Offline

Post October 29th, 2009, 9:03 am

You're using a table type with transactions available, right ?

I'm not sure the mysql_ functions support transactions, I've never tried. Something tells me those functions will basically default to an autocommit functionality. You should be using the mysqli functions when working with transactions.
Strong with this one, the sudo is.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Joined: Mar 12, 2007
  • Posts: 6228
  • Loc: South-Africa
  • Status: Offline

Post October 30th, 2009, 3:04 am

Yeah, the tables all do support transactions. Thanks for the link, that looks very impressive. I think I am going to see how I can implement that.
Let's leave all our *plum* where it is and go live in the jungle ...

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 173 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.