PHP只在数组中存储1048576个字符 [英] PHP only store 1048576 characters in array

查看:260
本文介绍了PHP只在数组中存储1048576个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个项目,解析大文本文件和存储在MySQL数据库的一些信息。我注意到一个字段缺少信息,当它显示时,但是,当检查DB(从phpmyadmin),它显示数据是完整的,所以问题必须与php,之前的数组字段的长度是1048576 ,而DB中有1235597个字符。

I'm working on a project that parses huge text files and store some of the information in MySQL DB. I noticed one of the field was missing info when it was displayed, however, when checking the DB (from phpmyadmin), it shows the data is complete, so the problem must be with the php, before the length of the array field is 1048576, whereas there are 1235597 characters in DB.

我的php信息显示memory_limit是2048M,
Mysql配置显示:
[mysqld]
key_buffer = 32M
max_allowed_pa​​cket = 32M

My php info shows memory_limit is 2048M, Mysql config shows: [mysqld] key_buffer = 32M max_allowed_packet = 32M

我不知道还有什么可能导致问题...有人请帮助!

I don't know what else could have caused the problem... someone please help!!!

感谢您,
Sean

Thanks, Sean

推荐答案

PDO的预设缓冲尺寸为1 MB(1048576),请尝试将其压缩至2 MB(2097152)

PDO's default buffer size is 1 MB (1048576), try bumping it up to 2 MB (2097152)

如果直接使用PDO,请将此作为第4个参数传递

If you are using PDO directly, pass this as the 4th argument

$pdo = new PDO(
    $dsn,
    $username,
    $password,
    array(PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => 2097152)
);

如果使用Laravel,可以通过config / database.php文件您的连接的选项数组

If you are using Laravel, this can be done via the config/database.php file by adding an array of options to your connection

// ...
    'mysql' => array(
        'driver'    => 'mysql',
        // ...
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'options'   => array(
            PDO::MYSQL_ATTR_MAX_BUFFER_SIZE => 2097152
        ),
    ),
// ...

这篇关于PHP只在数组中存储1048576个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆