Welcome Guest, Not a member yet? Register   Sign In
Handle Dynamic Database Loading
#1
Question 

Basically I am trying to convert my old control system, which is just plain PHP not MVC, to Code Igniter 3. The issue I am having is with how to properly load in databases, from a database. Basically what I have built currently, is a system that handles several servers through one system by loading the database server information from the database of the current system. An example of what I am talking about is below:

How my old system works:
PHP Code:
$getgrid $qls->SQL->query("SELECT * FROM grids WHERE id = '$gridid' AND gridowner = '$userid'");
while (
$row $qls->SQL->fetch_array($getgrid)) {
  
$grid_name $row['gridname'];
  
$grid_db_host $row['grid_db_host'];
  
$grid_db_name $row['grid_db_name'];
  
$grid_db_user $row['grid_db_user'];
  
$grid_db_pass $row['grid_db_pass'];
  
$grid_login_uri $row['grid_login_uri'];
}

$gridconnection = new mysqli($grid_db_host$grid_db_user$grid_db_pass$grid_db_name);
if (
$gridconnection->connect_errno) {
  
printf("Connect failed: %s\n"$gridconnection->connect_error);
  exit();


I am trying to figure out a way to do that cleanly with Code Igniter MVC, because the old way like in that is not via MVC. I hope this makes since...
Reply
#2

Once you retrieve the credentials, you can manually load and return a new database object.

http://www.codeigniter.com/user_guide/da...a-database
http://www.codeigniter.com/user_guide/da...-databases
Reply




Theme © iAndrew 2016 - Forum software by © MyBB