Is there anything wrong with creating a new object for every mysql query in my scripts?
Basicly I have 5 main mysql classes dbConnect, dbSelect, dbInsert, dbUpdate and dbDelete.
dbConnect does the obvious then each time im making a new query to the database I'm creating a new object. I've found this fairly helpfull but are there any drawbacks or disadvantages to it?
Creating a new object for every mysql query?
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Creating a new object for every mysql query?
The draw backs are that there is slightly more overhead.. although that is barely anything to squack about.
The advantage is each query is encapsulated and represented as it's own entity, instead of a collection of entities... which is good thing in this case because the queries are generally unrelated.
So generally speaking, it sounds like your on the right track.
The advantage is each query is encapsulated and represented as it's own entity, instead of a collection of entities... which is good thing in this case because the queries are generally unrelated.
So generally speaking, it sounds like your on the right track.
Re: Creating a new object for every mysql query?
thanks, glad to see I'm on the right track, it seemed to make sense to me.
I've got a couple of class related questions whilst I'm on the topic.
Using the example of creating a sort of blog/cms script
Should you create a separate class for every task like adding a new member, deleting posts, editing pages, or should I group common tasks together?
When should functions be used instead of classes? I'm finding myself possibly getting carried away and using classes for everything. In a lot of cases I'm simply using classes to contain several functions making them easier to access.
Thanks again for your help
I've got a couple of class related questions whilst I'm on the topic.
Using the example of creating a sort of blog/cms script
Should you create a separate class for every task like adding a new member, deleting posts, editing pages, or should I group common tasks together?
When should functions be used instead of classes? I'm finding myself possibly getting carried away and using classes for everything. In a lot of cases I'm simply using classes to contain several functions making them easier to access.
Thanks again for your help