0

I had a rather short question, doesn't OOP Programming make you increase the amount of executed queries?

class Guild{
	private $members[];
	private $sName;
	private $iLevel;
	
	function __construct($guildId)
	{
		// get all information from db using the guildid
		// also get all memberid's from the db and pass these trough
		// to the constructor of the Personclass.
	}
}

class Person{
	private $sName;
	
	function __construct($userid)
	{
		// now get my information from the db using my userid.
	}
}

And is there a way to do this diffrent?

Is it common by the way to use the constructor to get the information from the database and use the destruct it to save the modified fields?

Kind regards

3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Schoorsteen
0

Whether it had more queries or not would depend on how each piece of code is written. Intrinsically, it does not make more calls. If I were to do it different, I would probably make a separate function that makes all the mysql calls and call that from the constructor so that the constructor itself isn't too messy.

I'm not sure if it's common or not, but that certainly is one way of doing it. When I wrote a game with an OOP php backend, I would load the minimal data at startup upon initialization and then pull up additional information as needed. That way you don't need grab *everything* if not all is needed.

0

This really has nothing to do with OOP particularly, mostly it has to do with your setup.

The way I would do it to minimize queries would be to select all data with users that have that guild id. Then I would pass the user data into the person class using the constructor or individual methods. That way you are not querying the database for every user again.

Yes, I think its pretty common to use the constructor to get info and destructor to save/update it. Its something I use to cut down on the number of queries.

Edited by somedude3488: n/a

0

Thank you for this information and the quick response, it was certainly useful.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.