Should I use PHP OR MySQL ??

5 replies
Hello,

I need to discuss one thing.

Suppose,

I have a table in mysql database:

table1:
  • col_1

If I need to retrieve records in asc order from col_1, I can do this in two manners. One is I can simply use this 'ORDER BY col_1 ASC' in the end of the query. The 2nd way is I can use the php functions to sort my records in ascending order.

Should I use mysql or php to sort my records in asc order. If PHP then why ?? If mysql then why ??

What are its effects on our script related to time execution of our script ??

Thanks in advance.
#mysql #php
  • Profile picture of the author AndyBlackSEO
    You have to retrieve the records anyway using mySQL so why increase more work by then sorting it using PHP? Get the data you want in the order you want it using the mySQL query. That's why they have them.
    Signature
    [FREE SEO TOOL] Build 29 Effective, High Authority Backlinks that Will Increase Your Google Rankings in 2020... CLICK HERE ...
    ... Instant backlinks that can get you results within 24-72hrs.
    {{ DiscussionBoard.errors[3180386].message }}
  • Profile picture of the author Jilawatan
    I know it can be so comfortable to retrieve records via mysql but what I am trying to ask, if we are working with a large software having a huge database, then don't you think so that it can put a bit more load on our mysql server ??
    {{ DiscussionBoard.errors[3180477].message }}
    • Profile picture of the author Christopher Airey
      If you designed the table/database correctly, you'll be sorting on a primary key or an indexed field. The MySQL database is highly optimized to sort using these keys, so the overhead is going to be a LOT lower if you let the database do the heavy work. The stress you're putting on the MySQL server is going to be minimal compared to doing it via PHP. Also remember that if you're sorting with PHP, the server is going to have to process all of the rows and transmit them to you (presumably over a network if you're worried about putting an extra burden on the MySQL server), and the time it takes to do this will be exponentially longer than just letting MySQL sort and then send over the results to you.

      For basic sorts/queries on data that changes a lot, just let the database handle it. Yeah you may have more load on the database server, but that's its job. If it becomes an issue, you may either have to do some caching yourself or come up with a better solution (or database design).
      {{ DiscussionBoard.errors[3180493].message }}
      • Profile picture of the author mickster
        Database servers (MYSQL, SQL Server, Oracle and the like) are designed with one aim in mind - to handle ENORMOUS loads; that's where they come into their own. Any sorting that you need to do, definitely do it through MYSQL. It will add 1 millisecond or less to the processing time.
        Signature

        WARNING: Most eBooks SUCK! Make sure you check out The Secret Automated Income System for an easier shortcut to $1k per day...it's FREE, and it's going to be eye openening (without the need for you to spend a lot, and you don't need any experience either!)...

        {{ DiscussionBoard.errors[3180692].message }}
  • Profile picture of the author Jilawatan
    Thanks Christopher And Mickster for clearing my concept..
    {{ DiscussionBoard.errors[3180937].message }}

Trending Topics