duanhu2414 2019-06-24 08:34
浏览 152

没有SELECT:当其他无缓冲的查询处于活动状态时无法执行查询(INSERT INTO / ANALYZE TABLE / BEGIN TRANSACTION)

I got the error: General error: 2014 Cannot execute queries while other unbuffered queries are active. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute. But:

  1. PDO::MYSQL_ATTR_USE_BUFFERED_QUERY is ON
  2. I don't use pdo's query() just exec().

I think there is a Problem with "ANALYZE TABLE". It returns a resultset with on row. I don't need this information. I can't change the order of the sql commands because in real that a different batches that a called in the night by a cron job...

A test code:

pdo()->exec("TRUNCATE TABLE test;");
pdo()->exec("INSERT INTO test SELECT id FROM data");
//    pdo()->exec("INSERT INTO test VALUES (1)"); if only VALUES(..) is used no error thrown
pdo()->exec("ANALYZE TABLE test"); // this returns 1 row
pdo()->beginTransaction(); // here comes the exception!

The connection settings:

PDO::ATTR_EMULATE_PREPARES => 1
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => 1
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8, lc_time_names = 'de_DE',sql_mode ='STRICT_ALL_TABLES,PIPES_AS_CONCAT', group_concat_max_len=1000000" ; 
PDO::MYSQL_ATTR_COMPRESS => 1

My actual Workarround is:

$cmd = pdo()->query("ANALYZE TABLE test");
$cmd->closeCursor();
unset($cmd);

Is there any missconfiguration or is this a bug in 10.2.22-MariaDB-log or PHP Version 7.2.10?

  • 写回答

1条回答 默认 最新

  • dpklt4291 2019-06-24 08:46
    关注

    I don't use pdo's query() just exec().

    THIS is your problem exactly. Mysql has no idea whether you need the result or not. Or, rather, it assumes that as long as you made a request, the result it will be waiting for you. Hence, using exec() for a query that returns any data just makes no sense and also is the exact reason why you are getting the error.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料