⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Multi database setup



kaosweaver
  • profile picture
  • Member

Posted 21 May 2012 - 21:41 PM

New to Grocery CRUD, I attempted to search for a possible solution and wasn't able to find someone else with this issue.

I have multiple databases I connect to for my site (a sales database, an article database, a stats database) - I do this by having all of my models inherit from a master model which controls the setup dynamically by a constructor call (which sets the database configuration and loads the database) - I also use the parent class to switch the environment database settings (production, testing, dev), so, we're pretty messy when it comes to the configuration - but it is all working as it should for me. The down side is all of the database calls aren't on the main database class ($this->db->...) they are under DB2 ($this->DB2->....)

....

LOL - I answered my own question as I was typing that last bit - I simply did a search and replace on the database function call in the grocery_CRUD_Model from $this->db to $this->DB2 and it worked. (well, I've got to now figure out why the output isn't displaying right style/js paths and all, but it is pulling the correct database data)

I'll post just in case someone else wants to work with a varied database config and this helps (I did also have the grovery_CRUD_Model extend my master controller and updated the constructor to call the config setting per the database I wanted loaded, I'll make it dynamic in the future)

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 21 May 2012 - 21:48 PM

You don't need to. This question has been answered without changing the core functionality of grocery CRUD. /topic/420-answered-can-i-switch-databases/