i have seen there many ways "do sql" in models.
which method ok use?
if methods ok use, when should use them?
thanks
code: select all
$this->_db->setquery($query);
$db =& $this->getdbo();
$db->setquery( $query );
$db =& jfactory::getdbo();
$db->setquery( $query );
which method ok use?
if methods ok use, when should use them?
thanks
all 3 methods should work.
from within model, first best approach. outside of model, second best approach when doing operations on specific model. in other contexts, third best approach.
the third general, because @ point can use reference joomla! database object. reference same object stored model. jmodel::getdbo method returns reference _db variable, reference global database object, in (rare) cases not (and if haven't done specific make otherwise, same one). members of classes start _ private members, , should accessed within particular class. if have model object , trying access database outside, should reference database using getdbo() method.
hope helps,
ian
from within model, first best approach. outside of model, second best approach when doing operations on specific model. in other contexts, third best approach.
the third general, because @ point can use reference joomla! database object. reference same object stored model. jmodel::getdbo method returns reference _db variable, reference global database object, in (rare) cases not (and if haven't done specific make otherwise, same one). members of classes start _ private members, , should accessed within particular class. if have model object , trying access database outside, should reference database using getdbo() method.
hope helps,
ian
Comments
Post a Comment