Jump to content
Killersites Forums


New Members
  • Posts

  • Joined

  • Last visited

IndexOutOfBounds's Achievements


Newbie (1/14)



  1. Hehe, yes it does. I tried using the global $core at my actual pages, failing to realize that global is a keyword used in classes (at least, that's what I think it is). So I got it working now like I originally wanted. Once again, thank you so much
  2. Aha, I see. Thanks a lot again! I've been searching around a bit while awaiting a response, and I stumbled across the Singleton concept. As far as I can make out, I could implement that into this? -- Edit: Hmm, feel like a idiot now, so you'll have to forgive me if I'm doing some elementary wrong here. I've created the core class as per your above post, and inserted the "global $core;" in the php-file I'm working on. However, when I try $core->DB->do_connect(); I get the error, "Call to a member function do_connect() on a non-object in C:\xampp\htdocs\kelvin\crewlist.php on line 118". I'm guessing this is due to the core object not being initiated correctly? class Core{ public $DB; //public $Auth; function __construct(){ $this->DB = new dbconnect(); } } // Class to connect to DB. class dbconnect{ private $db_host = 'myhost.com'; private $db_user = 'mydb'; private $db_pass = 'myPassword'; private $db_database = 'myDB'; public $con; function __construct() { ; } function do_connect(){ $this->con = mysql_connect($this->db_host, $this->db_user, $this->db_pass) or die('Unable to establish a DB connection'); return mysql_select_db($this->db_database, $this->con); } }
  3. Thank you so much. Sorry if my first post was a bit confusing, when I read it trough now I saw that it wasn't entirely clear. I also noticed that I'm mixing between functions/methods and classes/objects ... .Anyway, I like the solution you provided, and particularly the last one. But I'm not quite sure what you mean by creating a object that contains other objects. Could you show me a simple example how I would go about doing this?
  4. Heya, so I've worked on PHP for a while, but only recently started to learn OOP. I've been following the tutorials here on killerphp, and started implementing OOP into a private project of mine. However, I've recently struck a bit of a problem which I assume is very easy to those of you that know OOP. So, the case: I've been creating a class that I've been using to connect to my DB. The connectdb -class contains two functions, one construct and one function that actually connects to the DB. All variables (with host information for the DB) are declared private inside the class. This have been working fine, but when I tried to take this a bit further I got stuck: I'm creating a new class (popup) that's meant to get data from the DB based on user input. What I want to do is make the popup class use methods from the connectdb -class, i.e connect to the DB. I tried something simple as connectdb::do_connect() inside a popup method, but this obviously didn't work as the connectdb -class hadn't been constructed. I also tried calling the construct method of the connectdb -class, but this only didn't work but also looked weird/wrong to me. Thus I'm stuck with making two handlers, one to create the connectdb -class and one for the popup -class. Is this really necessary? I'm not providing the code in this post, as I assume someone with experience knows this in the back of their heads Thanks for any replies.
  • Create New...