Hey,
I would like to get the input on how some of you handle calling methods that require a database connection.
Do you create a connection instance (maybe using a singleton class) in every method you know will use a connection?
Or do you just create a method that will connect and place it into your main project and call it once?
ie
public function connect() {} // handles connection
$user = new User();
$user->greet(); // doesn't require connection so no need to call connect method
//the next method requires a connection so take care of that first
$user->connect();
if ($user->isLoggedIn())
//Logged in
I think it’s the samething at the end of the day but it’s one less worry if you have connected to a database or not.
Let me know! thanks…