Welcome Guest, Not a member yet? Register   Sign In
Tricky Multi-site config
#1

[eluser]ccachor[/eluser]
So for the requirements of this new project I'm working on there will always be two databases (Users and XXX-Site). The reason for using multiple databases is because each client has inventory that is quite large, so putting it all into one table is a problem. So, instead each client will get their own database with a table for inventory, etc. The best way, I think, is to have the Users table include a field for the name of the second database it will use. There could be one user for multiple sites so that's the reason for that.

I have the multi-database config set up, but I'm just wondering how I would set the field in the config file to get that given database based on the query from the first database. It's difficult to explain I apologize. I've been looking at multi-database posts on the forum but I haven't come across one where the second database name changes dynamically!

Any help would greatly be appreciated Smile
#2

[eluser]tonanbarbarian[/eluser]
If you use models for all of your database interactions (and you should) then you can load a different database connection in each model if needed.

Normally I would suggest using the 3rd parameter of load->model but that will not work in this case.
so here is what you do

Model XYZ
Code:
class XYZ extends Model {

  function XYZ() {
    parent::Model();

    // returns and assigns the ABC database connection
    $this->_db =& $this->load->database('ABC', true);
  } // XYZ()

  function blah() {
    // use original database
    $query = $this->db->get('users');
    ...
  } // blah()

  function foo() {
    // use ABC database
    $query = $this->_db->get('users');
    ...
  } // foo()

} // class XYZ

Note this has not been tested but it should be close to what you need.
If you find it too confusing then change the new database connection from _db to something else.
#3

[eluser]ccachor[/eluser]
In my database connection class, how would I assign the second connection a variable? I need to connect to the first in order to select which database I'm loading with all my inventory so that's what I'm struggling with. Thanks for the quick reply, I'll try working with your solution.
#4

[eluser]Pygon[/eluser]
Actually, because of your question -- i started poking at the DB object more thoroughly.

Looks like there was a plan to (or used to be implemented) accepting a DSN when calling load->database(), however it doesn't appear that it was ever completed (atleast that I see)

You might consider modifying the first line of the DB() function:
Code:
if (is_string($params) AND strpos($params, '://') === FALSE)

to be:

Code:
if( !is_array($params) )

This will allow you to pass an array with the database configuration (hostname,password,username,dbdriver,active_r,etc...) to load->database.
#5

[eluser]ZeusChicago[/eluser]
Let me expand upon our question a little bit and explain the project were trying to setup (with Code ignitor)

We are going to designing several dozen sites, all of which basicly contain the same base code (access the database, reading inventory, looking up prices, etc) but each site will ahve its own "look and feel", basicly templates we design on top of the base code.

We have a dedicated server running Cpanel and have setup a "Reseller" account, and then each of the several dozen sites will be created as "Add-On" account to this account, so the directory stucture ends up looking like this

Reselller accounts
/home/reselleraccount/public_html

Add on accounts
/home/reselleraccount/public_html/site1
/home/reselleraccount/public_html/site2
/home/reselleraccount/public_html/site3
/home/reselleraccount/public_html/site4

In addition each site will need to access 1 common databse (login/password/site info). The first database will also contain the conection strings to connect to a second databse that contains site specific inventory for each site. These inventory database will be large enough (and for differant companys) so we would like to keep them in seperate databases for securty, peformance, etc).

What were trying to figure out is
A.) How to install/configure Code Ignitor so there is only one base install (so when we upgrade/patch CI, we only have to do it once)

B.) How to congifure CI so that we can have a "base" set of controlers/model/views shared by all sites that we can extend on each site to give them their own "look and feel". That way we dont have to update our base code everytime we find a bug.

C.) How to configure the database settings (which are in a config file) to be dynamic based on what the url is.

Hopefully that made some sence (and hopefully someone has a great thread to point us in the right direction!). I have done a bunch of searching on the forums and read through a bunch of Multisite threads and It looks like maybe I should check out Kohana, but given its new and not very active over there I would love to be able to accomplish this with CI.

Thanks!

Zeus
#6

[eluser]ZeusChicago[/eluser]
Might have found at least a partial answer here on the multi site, single CI install, shared core m/v/c and then site specific m.v.c for each site.

http://codeigniter.com/wiki/Multiple_App..._Symlinks/

Seems a tab bit complicated but it sounds like it works. are there any other easier ways before I go marching down this path?

Z
#7

[eluser]kutis[/eluser]
firstly, apologies for bumping old thread. but i figured since i have a question in the topic, i thought it might help other that have similar problem (less search result to go through)

situation at my hosting server:
/public_html/ (this is directly linked to site#1)
/public_html/site2.com/
/public_html/site3.com/
/public_html/site4.com/

and the question; is it possible to run a single install of CI? so the final result is:
/system (ci)
/public_html/application
/public_html/site2.com/index.php (maybe? running above application)
/public_html/site3.com/application (running another application)
/public_html/site4.com/ (running completely different app -- i know i could just leave this one alone)

if so, care to share the information?

thank you
#8

[eluser]TheFuzzy0ne[/eluser]
Yes, it's possible. This is why you shouldn't ever edit the core. In your case, you can just move the system directory to somewhere that's easily accessible by all of your apps, perhaps the Web root, or just outside the Web root. Then edit your index.php for all your apps to reflect the new application and system directories. You can also put your application directories out of the Web root if you choose to do so. The only thing that needs to be in your Web root, is the index.php.

EDIT: Here's an example directory structure:

+-system
+-app1
| +-application
+-app2
| +-application
+-app3
| +-application
+-htdocs
+-app1
| +-index.php
+-app2
| +-index.php
+-app3
+-index.php
#9

[eluser]xwero[/eluser]
The directory structure could look like this

/ci
/ci/system
/ci/application (site 1 and 2)
/ci/site3
/public_html/index.php
/public_html/site2.com/index.php
/public_html/site3.com/index.php
#10

[eluser]kutis[/eluser]
yes, thank you all. makes a lot of sense now




Theme © iAndrew 2016 - Forum software by © MyBB