Hallo!
Wenn du anfängst zu programmieren und dich mit Datenbanken beschäftigst, wirst du irgendwann auf dieses Problem stoßen. Text-Felder können in MySQL nicht eindeutig sein, aber es gibt eine sehr einfache Lösung: eine eindeutige Kennung, die dem Hash entspricht.
Nehmen wir an, wir haben den folgenden langen Text:
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
Wenn wir die Funktion https://www.php.net/manual/es/function.md5.php von php oder dieselbe von https://dev.mysql.com/doc/refman/8.0/en/encryption-functions.html#function_md5 verwenden, erhalten wir das folgende eindeutige Ergebnis:
01aad0e51fcd5582b307613842e4ffe5
Auf diese Weise hätten wir einen Hash, um zu überprüfen, ob er existiert oder nicht, ohne dass er viel Platz einnimmt (die Verschlüsselung verbraucht mehr CPU, aber keinen Speicherplatz in der Datenbank).
Die Funktion in php würde so aussehen:
<?php
$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
echo $string;
echo "<hr />";
echo md5($string);
?>
Deshalb müssten wir in der DB die folgenden Felder erstellen:
(eindeutig, varchar255) hash: 01aad0e51fcd5582b307613842e4ffe5 (Text, nicht als eindeutig gekennzeichnet) texto: Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.