来自同一连接的MySQL多个同时查询

时间:2016-09-24 20:29:24

标签: mysql

我正在尝试从具有相同数据库连接的PHP同时在MySQL服务器上运行多个查询。我在服务器上运行了SQL语句,但响应是预期的。我没有得到SQL异常,但根本没有SQL查询响应(结果为FALSE)。

这是因为您无法查询另一个查询何时在同一连接上处于活动状态?

代码从数据库表中加载人员姓名和上次付款日期信息的数据。这将以表单形式显示,然后用户可以选择更新付款的成员。然后,我坚持的部分是第二个查询,其中所选名称试图找到家庭的family_id。

代码段:

mysql_select_db($database_W3OITesting, $W3OITesting);
$yearnow = date("Y",strtotime('+1 year')).'-12-31';
$yearrecent = date("Y",strtotime('-1 year')).'-12-31';
$query_Recordset1 = "SELECT DISTINCT lname, fname, suffix, fcccall, members.member_id, MaxDateTime " .
"FROM members " .
"INNER JOIN " .
    "(SELECT paid.member_id, MAX(paid.year) AS MaxDateTime " .
    "FROM paid " .
    "GROUP BY paid.member_id) groupedpaid ".
    "ON members.member_id = groupedpaid.member_id " .
"Where (MaxDateTime < '$yearnow') AND ".
"(MaxDateTime >= '$yearrecent')" .
"ORDER BY lname, fname, suffix, fcccall";
$Recordset1 = mysql_query($query_Recordset1, $W3OITesting) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

 //if a post is received handle it here
 function getPostArray($array){
 foreach ($array as $key => $value){
    //search here for if this member is part of a family
    //if not part of a family just update the payment
    //record for the member with the value
    try {
        $query_Recordset3 = "SELECT lname, fname, suffix,                 `members`.member_id , `family`.member_id " .
             "FROM members, family " .
             "WHERE (`members`.member_id = `family`.member_id " .
             "AND `members`.member_id = $key)";
        echo $query_Recordset3. "<br>";
        $Recordset3 = mysql_query($query_Recordset3, $W3OITesting);
        $row_Recordset3 = mysql_fetch_assoc($Recordset3);
        $totalRows_Recordset3 = mysql_num_rows($Recordset3);
        echo $totalRows_Recordset3 . "<br>";
        echo "$key => $value";
        if($totalRows_Recordset3==FALSE) {//Recordset3 is always FALSE
          echo " Error - " . $row_Recordset3['lname'];
        }
        if($totalRows_Recordset3!=0) {
          echo " - A Family";
         } else { 
          echo " - Individual";
         }
        echo "<br>";
    }
    catch(Exception $e)
     {
      echo "Exception: $e";
      die();
     }
    if(is_array($value)){ //If $value is an array, get it also
        getPostArray($value);
    }  
} 

}

0 个答案:

没有答案