【发布时间】:2013-08-12 00:26:18
【问题描述】:
我试图问这个here,但结果并不好。我考虑过编辑,但鉴于已经收到的答案,我认为最好重新开始。
我收到以下错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: 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.' in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sustainable_water_allocation\LTOO_test.php:348 Stack trace: #0 C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sustainable_water_allocation\LTOO_test.php(348): PDOStatement->execute() #1 C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sustainable_water_allocation\ga.php(119): totalSI(Object(gaParent), 1) #2 C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sustainable_water_allocation\ga.php(266): GA->fitness(Object(gaParent), 'totalSI') #3 C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sustainable_water_allocation\LT in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\sustainable_water_allocation\LTOO_test.php on line 348
这是连接设置:
$this->dbh = new PDO($dsn, $user, $password, array(
PDO::ATTR_PERSISTENT => false,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::MYSQL_ATTR_USE_BUFFERED_QUERY =>true
));
这里是 MySQL 通用日志文件:
1 Connect
1 Query select rva from demand_nodes
1 Query select * from demand_nodes
1 Query select * from source_nodes
1 Query TRUNCATE TABLE `results_demand`;
1 Query TRUNCATE TABLE `results_link_input`;
1 Query TRUNCATE TABLE `results_source_state`;
1 Query TRUNCATE TABLE `results_supply`
1 Quit
下一个要运行的查询会产生错误。
查询是在实例化对象时生成的,如下所示:
$allSources = new sources();
为了更好的衡量,这里是所有列出的查询:
$sql = "select rva from demand_nodes";
$core = Core::getInstance();
$stmt = $core->dbh->prepare($sql);
if ($stmt->execute()) {
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$rVAs = $rVAs + $row['rva'];
$numOfDemands = $numOfDemands + 1;
}
$stmt->closeCursor();
}
$sql = "select * from demand_nodes";
$core = Core::getInstance();
$stmt = $core->dbh->prepare($sql);
$stmt->execute();
$row = $stmt->fetchAll();
foreach($row as $i=>$value){
$this->id[] = $row[$i]['id'];
$this->label[] = $row[$i]['label'];
$this->initialDelta[] = $row[$i]['initial_delta'];
$this->initialRate[] = $row[$i]['initial_rate'];
$this->deltaMin[] = $row[$i]['delta_min'];
$this->deltaMax[] = $row[$i]['delta_max'];
$this->rateMin[] = $row[$i]['rate_min'];
$this->rateMax[] = $row[$i]['rate_max'];
if($row[$i]['si_weight'] != 0){
$this->siWeight[] = $row[$i]['si_weight'];
}else{
$this->siWeight[] = 1/($numOfDemands + $rVAs);
}
$this->rva[] = $row[$i]['rva'];
}
和
$sql = "select * from source_nodes";
$core = Core::getInstance();
$stmt = $core->dbh->prepare($sql);
$stmt->execute();
$row = $stmt->fetchAll();
foreach($row as $i=>$value){
$this->id[] = $row[$i]['id'];
$this->label[] = $row[$i]['label'];
$this->state[] = $row[$i]['initial_state'];
}
难住了。我不知道还有什么要补充的,但如果我遗漏了什么,请告诉我。
【问题讨论】:
-
这次你做得更好但又一次:我们怎么知道
an object is being instantiated, like this:$allSources = new sources();时发生了什么?我们怎么能?此外,错误消息包含一个堆栈跟踪,可以帮助跟踪错误源。它被省略。 再次。请注意,要获得可靠的答案,您必须提出可靠的问题。 -
顺便说一句,你填充几十个独立数组(如
$this->id[])的想法相当很奇怪。此外,对demand_nodes的两个 查询看起来也相当 很奇怪。此外,您需要每个表中的所有条记录的这种设计看起来又相当很奇怪。 -
Strange 和我想的一样奇怪。这是造成问题的原因吗?正如我在上一篇文章中提到的,我几乎没有接受过正式的编程培训。这不是一个网站,它是我正在开发的水分配和优化模型。这样做对我来说很有意义,但如果它影响运行时性能或导致错误,我不介意更改它。如有任何需要,请随时提出;我包括了我认为重要的内容。我只关心解决方案。
-
这个错误意味着一些上层查询未完成。使用堆栈跟踪来确定调用者代码,在里面哦,这个循环被调用了。
-
我不知道该怎么做,但我会看看。与此同时 - 一般的 mysql 日志显示所有查询。所有查询设置都发布在问题中。任何会导致此错误的查询有什么问题吗?
标签: mysql pdo truncate buffered