mysql - General error 2014 with PDO buffer attribute set to true -


i attempted ask here, didn't come out well. considered editing, given answers received, thought better start over.

i receiving following error:

fatal error: uncaught exception 'pdoexception' message 'sqlstate[hy000]: general error: 2014 cannot execute queries while other unbuffered queries active. consider using pdostatement::fetchall(). alternatively, if code ever going run against mysql, may enable query buffering setting 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 

here connection setup:

$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             )); 

here mysql general log file:

    1 connect         1 query select rva demand_nodes     1 query select * demand_nodes     1 query select * 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 

the next query run generates error.

the queries generated when object being instantiated, this:

$allsources = new sources(); 

for measure, here of listed queries:

$sql = "select rva 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 * demand_nodes"; $core = core::getinstance(); $stmt = $core->dbh->prepare($sql); $stmt->execute(); $row = $stmt->fetchall();  foreach($row $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']; } 

and

$sql = "select * source_nodes"; $core = core::getinstance(); $stmt = $core->dbh->prepare($sql); $stmt->execute(); $row = $stmt->fetchall(); foreach($row $i=>$value){     $this->id[] = $row[$i]['id'];     $this->label[] = $row[$i]['label'];     $this->state[] = $row[$i]['initial_state']; } 

stumped. not sure else add, if missed something, please let me know.

answer:

turns out truncate statements needed closed cursor:

$sql = "truncate table  `results_demand`;     truncate table  `results_link_input`;     truncate table  `results_source_state`;     truncate table  `results_supply`;"; $core = core::getinstance(); $stmt = $core->dbh->prepare($sql); $stmt->execute(); $stmt->closecursor(); 

as why:

i readily admit don't understand why closecursor() required on truncate. mysql indicates truncate mapped delete innodb; there nothing in of documentation reviewed suggested 'why?'.

perhaps else can speak this.

40 + hours on this... =/ resolved!


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

.htaccess - Matching full URL in RewriteCond -