Few things you must never do when quering database

I’m putting this in here because I’ve done it myself and I’ve seen it done by others.
NEVER EVER use mysql_query() in a loop (like while(), for(), foreach() … ). It will slow down your script and drive you nuts. It’s the wrong way of doing anything you have in mind.

Another thing is using union(). If you have one big mysql query and you union the results of that one with some other query, well, that is going to be a hard bone to chew for your web server. Same thing applies to joins. The more joins you will use in your query, the longer the server will take to process it and the more resources will be consumed.

Sometimes, instead of a join is better to use 2 different mysql queries that will give the same result. It’s up to you to decide what the scenario will be. But you must always remember that if an application runs well with 100 rows in the database, that will change when you’ll have 10.000 rows.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: