2

我想开发一个短url系统,比如bitly,我的数据库有问题。我无法区分数据库中的 a 和 A 。

这是我保存在数据库中的内容:

1   aaaaaaa a   a   a   a   a   a   a   aaaaaaa 1340802562  
3   aaaaaab a   a   a   a   a   a   b   aaaaaab 1340802562  
5   aaaaaac a   a   a   a   a   a   c   aaaaaac 1340802562  
7   aaaaaad a   a   a   a   a   a   d   aaaaaad 1340802562

在 id 2,我应该有 aaaaaaB。这是表结构属性:

1   id  bigint(20)      UNSIGNED    Nu  None    AUTO_INCREMENT    Schimbare   Aruncă     More 
     2  combination varchar(8)  utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     3  a   varchar(2)  utf32_general_ci        Nu  None          Schimbare   Aruncă     More 
     4  b   varchar(2)  utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     5  c   varchar(2)  utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     6  d   varchar(2)  utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     7  e   varchar(2)  utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     8  f   varchar(2)  utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     9  g   varchar(2)  utf32_general_ci        Nu  None          Schimbare   Aruncă     More 
     10 url varchar(255)    utf8_general_ci     Nu  None          Schimbare   Aruncă     More 
     11 time    int(10)         Nu  None          Schimbare   Aruncă     More 
     12 status  int(10)         Nu  None          Schimbare   Aruncă     More 

这是代码:

<?php
require_once('Controller.php');

class ShortLink extends Controller {
  public $chars="aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPq1Qr2Rs3St4Tu5Uv6Vw7Wx8Xy9Yz0Z";
  public function generate() {
    $this->DBconnect();
    echo $length = strlen($this->chars);
    for($a=0;$a<$length;$a++) {
      for($b=0;$b<$length;$b++) {
        for($c=0;$c<$length;$c++) {
          for($d=0;$d<$length;$d++) {
            for($e=0;$e<$length;$e++) {
              for($f=0;$f<$length;$f++) {
                for($g=0;$g<$length;$g++) {
                  $combination = $this->chars[$a].$this->chars[$b].$this->chars[$c].$this->chars[$d].$this->chars[$e].$this->chars[$f].$this->chars[$g];
                  mysql_query("
                    INSERT INTO `short` (
                      `id`,
                      `combination`,
                      `a`,
                      `b`,
                      `c`,
                      `d`,
                      `e`,
                      `f`,
                      `g`,
                      `url`,
                      `time`,
                      `status`
                    )
                    VALUES (
                      NULL,  '".($combination)."', '".($this->chars[$a])."',  '".($this->chars[$b])."',  '".($this->chars[$c])."',  '".($this->chars[$d])."',  '".($this->chars[$e])."',  '".($this->chars[$f])."',  '".($this->chars[$g])."',  '".($combination)."',  '".(time())."',  '0');");
                }
              }
            }
          }
        }
      }
    }
    $this->DBdisconnect();
  }
}
$ShortLink = new ShortLink();
$ShortLink->generate();
?>
4

3 回答 3

11

看到所有这些了utf8_general_ci吗?该_ci部分表示排序规则不区分大小写。

http://dev.mysql.com/doc/refman/5.6/en/charset-unicode-sets.html

于 2012-06-27T13:19:50.627 回答
4

“a”与“A”相同的原因是您的排序规则:utf8_general_ci

末尾的“ci”代表“不区分大小写”。

您需要更改排序规则。

于 2012-06-27T13:20:14.713 回答
1

" LIKE BINARY" 可能会有所帮助

http://dev.mysql.com/doc/refman/5.1/en/string-comparison-functions.html#operator_like

于 2012-06-27T13:21:28.263 回答