MySql记录插入停止在181822行

时间:2018-07-19 21:01:52

标签: php mysql

我使用以下php代码生成了8000000个随机字符串,每个字符串的长度为25个字符;

<?php
require('rsources/conn/config.php'); //Config File Contains the Connection Paramters
ini_set('max_execution_time', 3600);
?>
<html>
<body>
<head>
<title>Code Generator</title>
</head>
<?php
function generateRandomString($length = 25) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

    for ($i = 0; $i < 8000000; $i++) {
        $newcode = generateRandomString();
        $sql = "INSERT INTO ftbl_codes (sid, code, is_active, used_by) SELECT IFNULL(MAX(sid)+1,1), '" . $newcode . "', '1', '' FROM ftbl_codes;";
        //echo generateRandomString() . "<br />";
        $result = mysql_query($sql,$connection);
        if ($result){
            echo '<b><font style="color:yellow;background-color:Green;">' . $i . ' : Code Generation Succeeded</font></b> : ' . $newcode . "<br />";
        }else{
            echo '<b><font style="color:red;background-color:black;">' . $i . ' : Code Generation FAILED</font></b> : ' . $newcode . " " . mysql_error() . "<br />";
        }
    }
?>
</body>
</html>

它应该生成要插入表中的代码;

CREATE TABLE `ftbl_codes` (
  `sid` bigint(20) NOT NULL,
  `code` varchar(25) NOT NULL,
  `is_active` tinyint(1) NOT NULL,
  `used_by` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

我正在使用Xampp,服务器版本:10.1.31-MariaDB。 插入工作正常,直到$ i达到181822。您能帮我了解问题出在哪里吗?

0 个答案:

没有答案