johnsmith153 Posted December 4, 2009 Share Posted December 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/184019-which-is-quicker-db-searching-or-php-searching/ Share on other sites More sharing options...
roopurt18 Posted December 4, 2009 Share Posted December 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/184019-which-is-quicker-db-searching-or-php-searching/#findComment-971536 Share on other sites More sharing options...
Alex Posted December 4, 2009 Share Posted December 4, 2009 Yea, and it might even be possible to do this all within one query, again, it depends on your circumstances. Quote Link to comment https://forums.phpfreaks.com/topic/184019-which-is-quicker-db-searching-or-php-searching/#findComment-971540 Share on other sites More sharing options...
PFMaBiSmAd Posted December 4, 2009 Share Posted December 4, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/184019-which-is-quicker-db-searching-or-php-searching/#findComment-971541 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.