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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.