PHP Classes

query in foreach statment

Recommend this page to a friend!

      PDO Multi Connection Class  >  All threads  >  query in foreach statment  >  (Un) Subscribe thread alerts  
Subject:query in foreach statment
Summary:query in foreach statment
Messages:2
Author:CamusHsu
Date:2018-03-19 09:25:47
 

 


  1. query in foreach statment   Reply   Report abuse  
Picture of CamusHsu CamusHsu - 2018-03-19 09:25:47
Dear Sir,

I need to query in foreach, the code as below

$rs = $db->query("SELECT * FROM `member` WHERE 1;");
foreach ($rs as $load){
$rs2 = $db->query("SELECT SUM(`reward_point`) total_point FROM `reward` WHERE `mem_id`='".$load['mem_id']."' GROUP BY `mem_id`;")
}

it display some error message as below
Error: 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.

I found the answer by google, I know that I can use closeCursor to solve the problem. But I don't know how to use closeCursor in your class.

May you help me to solve the issue?

Thank you!

Camus

  2. Re: query in foreach statment   Reply   Report abuse  
Picture of CamusHsu CamusHsu - 2018-03-20 08:51:48 - In reply to message 1 from CamusHsu
I solve the problem, sorry to bother you.

Camus

 
For more information send a message to info at phpclasses dot org.