JError has been deprecated in J3.x, in favour of PHP exceptions, as it intermixed 2 different programming concepts: logging and error handling (the logging side has now been implemented as JLog).
For your exact case, you can wrap your code in a try / catch block to get the error, as shown in this SO answer:
try {
...
$db->setQuery($query);
$result = $db->loadResult();
}
catch (Exception $e){
echo $e->getMessage();
}
Note that $database->execute()
is stated to NOT work in J2.5. You should use $database->query()
if you need an equivalent.
In Joomla 2.5 and 3.x the JDatabase
object methods updateRecord()
and insertRecord()
also throw errors you can catch if they fail:
try {
JFactory::getDbo()->updateObject('#_table_name', $data);
} catch (Exception $e) {
//...handle the exception
}
If you're developing for Joomla 3.x only, you can also use a try catch block with SQL transactions to get the error details:
$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);
}