arbis Posted October 7, 2013 Share Posted October 7, 2013 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! Quote Link to comment Share on other sites More sharing options...
trq Posted October 7, 2013 Share Posted October 7, 2013 The global keyword is a terrible idea. You need to actually pass your connection in through the construct if it supports it, or some other method. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.