• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dynamic Database Connections

#1
[eluser]Alsweetex[/eluser]
Hi all,

I'm about to undertake a particularly large project and have decided to use CodeIgniter. I've only ever used it for small projects before so I thought I'd try it out at scale. My problem is that this application will be used to support a potentially unlimited number of clients who for space, performance and security reasons will end up getting their own database server on our network, or simply use their own database server depending on how they choose use our software.

So, my problem is that my main database that has our clients will be storing a list of database connection details against each one. I realise this isn't the only option, nor probably the best option, to scale an application but it's the one we're initially going with until the project proves to be a success.

So my question is:

Can I use CodeIgniter to connect to a database with connection variables from a database?

I was planning on getting the application to just rewrite the database config file in order to list all of the connections and then depending on the clients session load the correct for that client ($this->load->database($ClientDB, true)Wink. Is there a better way of doing this, like using hooks?

Many thanks for your time.

#2
[eluser]Piter[/eluser]
Hi!

How do you hook up is not the most limited number of databases for load-> database ()

Just setting the configuration and returns the connection object to the database.
Code:
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$config['dbdriver'] = "mysql";
$config['dbprefix'] = "";
$config['pconnect'] = FALSE;
$config['db_debug'] = TRUE;
$config['cache_on'] = FALSE;
$config['cachedir'] = "";
$config['char_set'] = "utf8";
$config['dbcollat'] = "utf8_general_ci";

$this->load->database($config);
http://ellislab.com/codeigniter/user-gui...oader.html
http://ellislab.com/codeigniter/user-gui...cting.html

#3
[eluser]Alsweetex[/eluser]
Wow, that makes it a lot easier!

Thanks for the fast response Smile

#4
[eluser]Robert Fulton[/eluser]
my problem is that my main database that has our clients will be storing a list of database connection details against each one.

[url="http://movie.stepaheadzone.com"]mediafire movie[/url]

#5
[eluser]Alsweetex[/eluser]
[quote author="Robert Fulton" date="1330422689"]my problem is that my main database that has our clients will be storing a list of database connection details against each one. [/quote]

Yes, this can be considered a problem in and of its self. If you have any suggestions I will listen.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.