php 生成随机字符串

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/technofiend/article/details/77596067
<?php
    function generateRandomString($length = 15) {
        return substr(str_shuffle(str_repeat($x='0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length/strlen($x)))), 1, $length);
    }

    $db   = new PDO('mysql:host=127.0.0.1;dbname=random', 'root', 'xxxxxxx');
    $stmt = $db->prepare("INSERT INTO random(`random`) VALUES(?);");

    for ($i = 0; $i <= 150000; $i++) {
        $stmt->execute(array(generateRandomString()));
    }

猜你喜欢

转载自blog.csdn.net/technofiend/article/details/77596067