class in session?
Posted: Mon Mar 24, 2008 10:08 pm
Is it okay to put a class into a session variable?
Say a database class for instance?
This way my database class only has to make one connection, and all of my modules can use it, then close at the very end?
Otherwise, right now I'm created the database class at the top, then passing it to the needed classes
Example
index.php
Is it okay to do it this way? So that my other pages just have to refer to the session instance of the class?
index.php
Say a database class for instance?
This way my database class only has to make one connection, and all of my modules can use it, then close at the very end?
Otherwise, right now I'm created the database class at the top, then passing it to the needed classes
Example
index.php
Code: Select all
$database = new Database();
$database->connect();
$login = new Login($database);
$page = new Page($database, "Index.html");
$database->close();
index.php
Code: Select all
$_SESSION['database'] = new Database();
$_SESSION['database']->connect();
$login = new Login();
$page = new Page("Index.html");
$_SESSION['database']->close();