Jump to content

Which is quicker: db searching or PHP searching?


johnsmith153

Recommended Posts

I need to pull various data, sort it etc.

 

We may be talking about pulling only 300-500 records, but db could hold thousands in total (that don't need to be pulled out).

 

Is it quicker to?:

 

(a) Pull all (300-500) records from db, then use PHP to further sort these into required 3 groups (by using while to sort through all 300-500 and then sort into 3 new arrays). Then display all as needed.

 

(b) Do 3 quick searches on the database one after another so all 3 come out perfectly sorted, ready to display. I.e. db could return 300-500 in total over 3 searches but may return 150, 80, 140 etc.

 

It probably won't make a major difference, but thought I would do it the right way. I would say (b) but my code would simply do 3 searches on the same db one after another, which would be nearly identical. Is this ok?

 

Please only respond if you know this for efinite, not what you 'think' may be best. Thanks.

Link to comment
Share on other sites

Please only respond if you know this for efinite, not what you 'think' may be best. Thanks.

 

What is best depends on your criteria and circumstances.  In any case, the database is usually faster than PHP code.

 

(edit) In addition, the database already supports a grammar for conducting searches with very little effort on your part, whereas in PHP you'll have to potentially write a lot of code to conduct the same searches.

Link to comment
Share on other sites

You execute one query that retrieves the rows you want in the order you want, then you just iterate over the rows in your php presentation code.

 

(a) You can do all the sorting in the query (which uses the complied code of database engine to do the work.) There is no need to use some slow parsed, tokenized, interpreted php code to do any sorting.

 

(b) It can be done in a single query.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.