title: Which MySQL collation exactly matches PHP's string comparison?
body: <p>Here is a MySQL query:</p>
  
  <pre><code>SELECT last_name FROM users ORDER BY last_name
  </code></pre>
  
  <p>We get all that data into PHP and then run:</p>
  
  <pre><code>$prior = NULL;
  do {
      $current = array_shift($results);
      assert($current &gt;= $prior);
      $prior = $current;
  } while ($current !== NULL);
  </code></pre>
  
  <p>Currently this assertion fails for certain inputs. Is it possible to add a COLLATE clause to the MySQL query above to absolutely guarantee that PHP assertion?</p>
  
  <hr>
  
  <p>Stuff I tried:</p>
  
  <ul>
  <li>The above code, it doesn't work for certain non-ASCII inputs</li>
  <li><code>ORDER BY email COLLATE utf8_bin</code> resulted in <code>COLLATION 'utf8_bin' is not valid for CHARACTER SET 'latin1'</code></li>
  <li>Maybe this is a duplicate of <a href="https://stackoverflow.com/questions/367711/what-is-the-best-collation-to-use-for-mysql-with-php">What is the best collation to use for MySQL with PHP?</a> but that seemed more subjective, I am seeking a specific answer to a specific problem</li>
  </ul>
  
  <hr>
  
  <p>Others notes:</p>
  
  <ul>
  <li>If it makes a difference, this column is <code>latin1</code></li>
  <li>My PHP PDO wrapper library is <a href="https://github.com/fulldecent/thin-pdo" rel="nofollow">https://github.com/fulldecent/thin-pdo</a></li>
  </ul>