ここで質問してみましたが、うまくいきませんでした。編集を検討しましたが、すでに回答が寄せられているため、最初からやり直した方がよいと考えました。
次のエラーが表示されます。
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'];
}
困惑した。他に何を追加すればよいかわかりませんが、何か見逃している場合はお知らせください。