I'm inserting data to a table in Joomla
foreach($resultarray as $data1)
{
$table = JTable::getInstance('Upload', 'UsersTable', array());
$table->bind($data1);
$table->store();
}
I want to do a transaction so that there will be START TRANSACTION, COMMIT
How to do it?
Joomla Joomla 3.x introduced SQL transactions (where supported) via the JDatabaseDriver's transactionStart, transactionCommit and transactionRollback. This supersedes the queryBatch method which was introduced in Joomla Joomla 2.5.
$db = JFactory::getDbo();
try
{
$db->transactionStart();
$query = $db->getQuery(true);
$values = array($db->quote('TEST_CONSTANT'), $db->quote('Custom'), $db->quote('/path/to/translation.ini'));
$query->insert($db->quoteName('#__overrider'));
$query->columns($db->quoteName(array('constant', 'string', 'file')));
$query->values(implode(',',$values));
$db->setQuery($query);
$result = $db->execute();
$db->transactionCommit();
}
catch (Exception $e)
{
// catch any database errors.
$db->transactionRollback();
JErrorPage::render($e);
}
i have picked this example from here