Which MySQL collation exactly matches PHP's string comparison?

Here is a MySQL query:

SELECT last_name FROM users ORDER BY last_name

We get all that data into PHP and then run:

$prior = NULL;
do {
    $current = array_shift($results);
    assert($current >= $prior);
    $prior = $current;
} while ($current !== NULL);

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?


Stuff I tried:

  • The above code, it doesn't work for certain non-ASCII inputs
  • ORDER BY email COLLATE utf8_bin resulted in COLLATION 'utf8_bin' is not valid for CHARACTER SET 'latin1'
  • Maybe this is a duplicate of What is the best collation to use for MySQL with PHP? but that seemed more subjective, I am seeking a specific answer to a specific problem

  • Others notes:

  • If it makes a difference, this column is latin1
  • My PHP PDO wrapper library is https://github.com/fulldecent/thin-pdo

  • echo ('a' == 'A') ? 'a==A ' : 'a <> A ';
    echo ('a' == 'á') ? 'a==á ' : 'a <> á ';
    

    两者都返回<> ,所以我推断PHP的行为就像latin1_bin (或者你拥有的任何charset的_bin )。

    链接地址: http://www.djcxy.com/p/25174.html

    上一篇: 做一个utf8

    下一篇: 哪种MySQL整理与PHP的字符串比较完全匹配?