Hướng dẫn php random string unique

How to make a random string unique to the string in the column below?

Hướng dẫn php random string unique


asked Mar 6 at 11:58

6

query("SELECT * FROM TABLE_NAME WHERE string='$string')")->num_rows;
        while($count != 0){
            $string = getName($length);
            $count  = $dbConnection->query("SELECT * FROM TABLE_NAME WHERE string='$string')")->num_rows;
        }
        return $string;
    }

    echo getUniqueString($n, $dbConnection);
?>

answered Mar 6 at 12:07

Hướng dẫn php random string unique

2

You can use openssl_random_pseudo_bytes() or random_bytes() PHP fonction to generate random strings.

You can also rely on MySQL to generate uniq IDs :

INSERT INTO mytable (alphaID) VALUES (REPLACE( UUID(), '-', '' )); 

answered Mar 6 at 14:26

Hướng dẫn php random string unique

AlaindeseineAlaindeseine

1,5721 gold badge6 silver badges17 bronze badges

Not the answer you're looking for? Browse other questions tagged php laravel random or ask your own question.