我试图在这里问这个,但结果并不好。我考虑过编辑,但鉴于已经收到的答案,我认为最好重新开始。
我收到以下错误:
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'];
}
难住了。我不确定还要添加什么,但如果我错过了什么,请告诉我。