Jump to content

Dynamic Database Connection using variables


arbis

Recommended Posts

I am having a lot of trouble with a variable scoping issue.  PHP and OOP is definitely not my strong suit but I'm trying to get this code working:

 

if (!empty($_POST["username"])){
        $connectdb=$_POST["username"];
        }else{
        $connectdb=$_GET["username"];
        }

class Main extends CI_Controller {

    function __construct()
    {   
        parent::__construct();

        global $connectdb;
        $this->load->database($connectdb);
        $this->load->helper('url');
        $this->load->library('grocery_CRUD');
        
    }
 

The idea is to get a user name from a previous login screen and set it to the variable $connectdb.  The variable doesn't stay through multiple instances of the constructor.  Can someone help!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.