Hi everyone hope you can help me with this issue, I'm trying to make a login system that is object oriented so I have the following classes:
- MySQLDB: Peforms all database operations, adding/removing members, checking passwords and usernames, also performing querys.
- Session: Performs Session actions(log in/out, keeping track of guests )
The Session class needs the MySQLDB class but DOES NOT inherit it, so after I define the MySQLDB class I also instance it as a global variable ($database), then I define the Session class, I know the basics of OOP and stuff, but the part which confuses me is that if the database object should be instanced within the Session class definition (as a member of Session) or outside with global scope (as an independent object), I think it should be instanced within the session class, but the login example which I'm being based initializes the database outside of session and redeclares it as global each time a method of session requires it, this is the original script I'm using as a guide, a bit old but very clear (except for that hehe) Login System also here's my code it's a simplified version to better illustrate my point.
database.php
<?php
class MySQLDB
{
private $link;
private $etcetera;
}
//Instanced outside of Session
global $database;
$database = new MySQLDB();
?>
session.php
<?php
include "database.php";
class session
{
/*OR instance the database object here so it can be accessed from the diffrent functions*/
private $database= new MySQLDB();
function login($member,$password)
{
global $database; //or here?, every time a function needs it
}
}
?>
Regards,Triztian