title: Doing calculations in MySQL vs PHP
body: <p>Context: </p>
  
  <ul>
  <li>We have a PHP/MySQL application. </li>
  <li>Some portions of the calculations are done in SQL directly. eg: All users created in the last 24 hours would be returned via an SQL query ( NOW() – 1 day)</li>
  </ul>
  
  <p>There's a debate going on between a fellow developer and me where I'm having the opinion that we should:</p>
  
  <p>A. Keep all calculations / code / logic in PHP and treat MySQL as a 'dumb' repository of information</p>
  
  <p>His opinion:</p>
  
  <p>B. Do a mix and match depending on whats easier / faster. <a href="http://www.onextrapixel.com/2010/06/23/mysql-has-functions-part-5-php-vs-mysql-performance/" rel="noreferrer">http://www.onextrapixel.com/2010/06/23/mysql-has-functions-part-5-php-vs-mysql-performance/</a></p>
  
  <p>I'm looking at maintainability point-of-view. He's looking at speed (which as the article points out, some operations are faster in MySQL).</p>
  
  <hr>
  
  <p>@bob-the-destroyer
  @tekretic
  @OMG Ponies 
  @mu is too short 
  @Tudor Constantin
  @tandu 
  @Harley</p>
  
  <p>I agree (and quite obviously) efficient WHERE clauses belong in the SQL level. However, what about examples like:</p>
  
  <ol>
  <li>Calculating a 24 period using NOW() - 1 day in SQL to select all users created in last 24 hours?</li>
  <li>Return capitalized first name and last name of all users?</li>
  <li>Concatenating a string?</li>
  <li>(thoughts, folks?)</li>
  </ol>
  
  <p>Clear examples belonging in the SQL domain:</p>
  
  <ol>
  <li>specific WHERE selections</li>
  <li>Nested SQL statements</li>
  <li>Ordering / Sorting</li>
  <li>Selecting DISTINCT items</li>
  <li>Counting rows / items</li>
  </ol>