Jump to content

[SOLVED] Class within a class


SetToLoki

Recommended Posts

hi I am creating a new class and I want to use my previously connected mysql class inside of it, being able to reference the mysql inside the new class I am creating.

 

example of what I tried to do

 

<?php
class user {
 private $user = "";
 private $userlevel = "";

 private $db;
 public function _construct()
 {
 	global $db_host, $db_user, $db_pass, $db_name;
 	$this->db = new MySQL($db_host, $db_user, $db_pass, $db_name);
 }

        function test()
        {
                $sql = "SOME SQL CODE";
                $results = $this->db->query($sql);
 	$rows = $this->db->fetch_assoc($results);	
        } 
}
?>

Link to comment
https://forums.phpfreaks.com/topic/163629-solved-class-within-a-class/
Share on other sites

Actually, just saw it,

 

_construct()

 

For the constructor to run automatically on instantiation you require two underscores;

 

__construct()

 

how embarrassing for me :(, sometimes I guess just look to hard and make it all complex when the answer is obvious, thanks my good man/lady!

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.