Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have this problem all the time. I've gone from using an auto-incremented primary to using an md5 hash most of the time. So while I haven't implemented this myself yet - no opportunity/need presently - you could do create a primary key (VARCHAR 32) that is an md5 hash of the first and last name. Like this:</p> <pre><code>$key = md5(strtolower($firstName . $lastName)); </code></pre> <p>Make the column this key goes into te primary key. Then you use an <code>INSERT IGNORE</code> and you can ignore any errors.</p> <p>Then you run a <code>SELECT</code> on the $key to return everything related to <code>$key</code>and display any info you have on the user in a friendly format. You don't have to show the user an error at that point, simply provide them with the info already captured. If you are worried about users with the same name seeing each other's data then the data can be obfuscated. For example instead of showing a phone number (333) 444-5555 you show (333) 444-5*<em>5 or (333) *</em>*-5555. Something that gives the user enough info to know if it is them or someone else with the same name.</p> <p>Typically I've used the <code>SELECT</code>, if empty <code>INSERT</code> and <code>SELECT</code> again, method. And it works but it is significantly slower than a simple <code>INSERT IGNORE</code> and then <code>SELECT</code>. I use a DAO I've built on top of PDO and the <code>INSERT IGNORE</code> works fine when a single column is the primary key. I have not tried it on a primary key based on more than 1 column nor have I tried it with the mysqli_* function.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload