MySql Rollback

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

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?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13503
  • Loc: Florida

Post 3+ Months Ago

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.
  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

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.

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 107 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.