Welcome Guest, Not a member yet? Register   Sign In
Active Record dbprefix... sort of
#2

[eluser]xwero[/eluser]
As an alternative you could use prefix variables in your model.
Code:
class Mymodel extends Model
{
   var $pf;
  
   function Mymodel()
   {
     parent::Model();
     $this->pf = array('mos_','my_','os_');
   }

   function query()
   {
      $this->db->select($this->pf[0].'users.username, '.$this->pf[1].'products.name, '.$this->pf[2].'orders.amount');
      $this->db->from($this->pf[0].'users');
      $this->db->join($this->pf[1].'products', $this->pf[0].'users.id='.$this->pf[0].'products.manufacturer_id');
      $this->db->join($this->pf[2].'orders', $this->pf[1]'products.id='.$this->pf[2].'orders.product_id');
   }

}
This means less processing. But for a query like in the example i would use table aliases which would make the query more readable.
Code:
$this->db->select('t1.username, t2.name, t3.amount');
      $this->db->from($this->pf[0].'users t1');
      $this->db->join($this->pf[1].'products t2', 't2.id=t1.manufacturer_id');
      $this->db->join($this->pf[2].'orders t3', 't2.id=t3.product_id');
If the prefixes are site wide you can add your own config file with the prefixes.


Messages In This Thread
Active Record dbprefix... sort of - by El Forum - 01-14-2008, 01:10 AM
Active Record dbprefix... sort of - by El Forum - 01-14-2008, 01:39 AM



Theme © iAndrew 2016 - Forum software by © MyBB