I was trying to develop Joomla 2.5 and 3 component. As many things deprecated between these two versions and the way to throw and catch database and other errors, I could not find ways yet to make single component for both 2.5 and 3.
So is making component separately for 2.5 and 3.
Firstly, in 2.5 this way I am catching an error in database: -
if(!$database->query())
{
return false;
}
But how do I show or return exact error message to the view class so that error is displayed in the component?
Secondly, for another kind of db query, I am getting data from db this way in model class (here is my code in model's function):
$this->_data = null;
if(JFactory::getApplication()->input->get('id') > 0) {
$db = JFactory::getDBO();
$db->setQuery("select * from `#__tablename_wrong` where `id`='".JFactory::getApplication()->input->get('id')."'");
}
if ($db->getErrorNum()) {
JError::raiseWarning(500, $db->getErrorMsg());
}
$this->_data = $db->loadObject();
return $this->_data;
Now I can inspect $this->_data
in view class to see if 0 records return but again how do I display a specific database error message or return an error message to my view class to show errors?
So these are the most common ways developers should show errors while doing database queries in 2.5.