我需要创建一个密钥生成器,我需要从数据库中检查该密钥是否不存在。如果密钥已经存在,我想生成另一个密钥并检查是否存在该密钥,直到我得到一个不存在的密钥。这就是我所拥有的,如果它存在,它就不会返回任何东西。
function checkHash($hash) {
include 'config.php'; //This calls for the DB
$checkhash = "SELECT * FROM orders WHERE uuid='$hash'";
$resultcheck = mysqli_query($db, $checkhash);
if(mysqli_num_rows($resultcheck) == 0) {
return $hash;
} else {
$orderhash = generateRandomString("15"); //The function that generates the key is generateRandomString();
checkHash($orderhash); //This re-runs the check function with a new key
}
echo generateRandomString("15"); //The 15 means how many characters in the key