duanfaxin7014 2014-09-08 14:25
浏览 211
已采纳

Pdo Mysql:警告:数据包乱序

I get the error "Uncaught Exception Warning: Packets out of order. Expected 1 received 166. Packet size=52" when running two PDO queries one after the other.

$dbh = new \PDO('mysql:host=' . $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass, array(
            \PDO::MYSQL_ATTR_LOCAL_INFILE => true
        ));

$sql = <<<eof
            LOAD DATA LOCAL INFILE '$csv'
             INTO TABLE $table
             FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"'
             LINES TERMINATED BY '
'
             IGNORE 1 LINES
            ($columns);
            ALTER TABLE $table ADD COLUMN disabled INT DEFAULT 0
eof;
$dbh->query($sql);
$sql = 'SELECT COUNT(id) FROM '.$table.' WHERE myfield IS NULL';
$dbh->query($sql);

What I'm trying to do : after import of large CSV file (about 30 MB and 40k lines) into database, I want to count how many rows are empty in a field, to fill them in a later query.

I noticed I can run the first query if I comment out the second one, and then I can run the second query if I comment out the first one. If I try to run them one after the other, it fails. I tried raising memory packet to 20M from 8M, and also to set $dbh->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true); with no success. Similar code worked with a smaller dataset earlier. Any pointers very welcome!

  • 写回答

2条回答 默认 最新

  • dongzhan8001 2014-09-08 16:13
    关注

    Ok so actually in the eof statement above I had put more than one query. After the load data inline I had added some alter table queries. It seems pdo can't handle several queries in one eof block. so I tried separating each query in its own request, and then it worked.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀