Advertisement

Using transaction on Joomla

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
saferamirez
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Feb 24, 2010 5:45 pm

Using transaction on Joomla

Post by saferamirez » Wed Feb 24, 2010 6:02 pm

Hi!

I want to know how I can make multiple entries in the database through a transaction. I need to ensure that all inserts are executed.

I tried using the JDatabase class methods, which allows you to create transactions, the method is BeginTrans the problem is that by default is configured autocomit BD so that any decision I make is reflected in the bd. How can I temporarily disable this property from the joomla code?

Thanks...

Advertisement
User avatar
Ratmil
Joomla! Explorer
Joomla! Explorer
Posts: 318
Joined: Sat Dec 06, 2008 7:07 pm

Re: Using transaction on Joomla

Post by Ratmil » Wed Feb 24, 2010 9:49 pm

Code: Select all

$db =& JFactory::getDBO();
$db->setQuery("START TRANSACTION");
$db->query();
....

Code: Select all

if($result)
{
    $db->setQuery("COMMIT");
    $result = $db->query();
}
else
{
    $db->setQuery("ROLLBACK");
    $db->query();
}
Have you noticed that the BeginTrans method in JDatabase is empty?
Your tables have to be of type InnoDB for transactions to work.

Advertisement

Locked

Return to “Joomla! 1.5 Coding”