Jump to content

Recommended Posts

I'm attempting to run a singleton-pattern on my MySQL Database Class and I'm running into problems referencing over to it...example:

 

On the login page itself:

$user = new User; // loading through the __autoload function and does work
//...IRRELEVANT PHP CODE...
$validate = $user->login($_POST['email'], $_POST['password']);

 

Within the User->login function:

public function login($email, $pass)
{
echo("INSIDE LOGIN");
$sql = MySQL::getinstance();
die("CREATED MYSQL INSTANCE");
        //...ADDITIONAL IRRELEVANT CODE...

 

Within the MySQL::getinstance(); function:

public static function getinstance()
{
if(self::$instance == NULL) self::$instance = new MySQL;
return self::$instance;
}

 

The "echo" and "die" within the User->login() function are just for debugging.  I will always reach the echo, but never reach the die...therefore, the problem is definitely in the MySQL::getinstance() line...

 

...thing is...I can't figure out what's wrong with the structure?

 

The MySQL class and User class are in separate files...but that shouldn't matter with the __autoload function, correct?

Link to comment
https://forums.phpfreaks.com/topic/88093-solved-singleton-patterning-challenge/
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.