PHP/SQL: ORDER BY or sort($array)?

后端 未结 6 1069
你的背包
你的背包 2020-12-19 05:36

Which do you think is faster in a PHP script:

$query = \"SELECT... FROM ... ORDER BY first_val\";

or

while($row = odbc_fet         


        
6条回答
  •  执念已碎
    2020-12-19 05:57

    Which do you think is faster in a php script:

    The ORDER BY doesn't execute in the PHP script -- it executes in the database, before data is retrieved by the PHP script. Apologies if this seems pedantic, I just want to make sure you understand this.

    Anyway, the reason I would use ORDER BY is that the database has access to indexes and cached pages from the database. Sorting in PHP sorts the data set in memory of course, but has no access to any index.

提交回复
热议问题