I've written a fairly simple database class in PHP that supports the most basic stuff such as connecting/disconnecting, querying, fetching data etc.
I know I'm reinventing the wheel here but there is some learning aspects behind this. I've tested it out and it works well. Now I want to make use of this class for a website I run that I know have a fair amount of simultaneous users at any given time and I found myself somewhat uncertain as to how to use the class.
Do I create a new instance each time I want to use the class? Lets say I have a function that lists something i my database, do I do something like this?:
function listStuff() {
$db = new Database();
$db->connect();
$result = $db->query($someQuery);
//do stuff with result
$db->dicsonnect();
}
This seems to create an unnecessary amount of objects in memory, so how would I go about it to reuse objects but still be able to have simultaneous users?
Thanks!