致命错误:允许的内存大小134217728字节已用完(试图分配35字节)


Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 35 bytes)

我正试图在数据库中插入一些序列号。我已经定义了这个范围,并制作了一个函数,如果我已经插入了相关的序列号,它会返回最后一条记录并递增。然而,当我试图增加结果时,代码中出现了一个错误。如果我硬编码它,它会很好地工作,但当我试图增加值时就不行了:

$batch = $_POST['batch'];
$serial=11111111;
if(array_key_exists('batch',$_POST)){
    $query="select serial from serials where serial like";
    $query.="'".$_POST['batch']."%'";
    $query.='order by serial DESC limit 0,1';
    $rs=mysql_query($query);
    while($row= mysql_fetch_assoc($rs)){
        $a =($row[serial]);
        $a = substr($a,0,2);// substring to match the string
        if($a == $batch){
        $a2 =($row[serial]);
        $a2 = substr($a2,2,-1);//substring to get the serial
        $serial =$a2;
        }
        else
        {
        $serial=11111111;
        };
    }
}
function createColumnsArray($end_column, $first_letters = ''){
    $columns = array();
    $length = strlen($v);
    $letters = range($serial,11111999); //(12847017, 12847027);
    foreach ($letters as $letter){
        $column = $first_letters.$_POST['batch'].$letter.'Z';
        $columns[].=$column;
        if ($column == $end_column)
        return $columns;
    }
    foreach ($columns as $column){
        if (!in_array($end_column, $columns) && strlen($column) < $length) {
        $new_columns = createColumnsArray($end_column, $column);
        // Merge the new columns which were created with the final columns array.
        $columns = array_merge($columns, $new_columns);
        }
    }
return $columns;
}

这是因为您的内存限制尝试

ini_set('memory_limit', '256M');

134217728字节=128 MB

或者考虑重写一个高效的代码,这样它会消耗更少的内存。。

Try...
Allowed memory size maximum. Put the code top of the file
ini_set('memory_limit', '-1');
相关文章: