MySQL Error - Cannot execute queries while other unbuffered queries are active

Hello All,I am using 7 different SQL statements in Row_inserted/Row_Inserting for many calculations, after execution, getting the below error.

…\MySQL\ExceptionConverter.php(119): An exception occurred while executing a query: 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 am very new to this error, Kindly suggest to me how to resolve this error in project-based file/sPhpmaker version 22.11, Mysql 8.1, Php >7Thanks for reading it.

You may post your code for discussion.

Sir, Thanks you very much for reply, please have the code belowPlease note the below information to understand the code
Inventorybook and InventorybookItems are main table to store totals incomming stock they are linked.
InventoryBook store cleint information and inventorybookItem store incoming stcok.
OinventoryBook and oinventrybookitems are as above to store outgoing stock.
What I am doing ; When outgoing stock is added in oinventoryitem, it should select the total values of outgoing itmes and submit to oinventorybook first and pass the common values to each other in below code like eployee id, client id etc.Than it update the incomed item balance in inventrybookitems with CODE(1-4) and
than
Update the totals incomed item stock value in Main inventoryBook table. with CODE (1-5)
in main inventorybook table CODE(1-5), there is a condition to check if the outgoing stcok days are less then 7 days from the incoming stock date minus the total outgoing weight from Total available weight.All code works, but when I apply 7 day condition then it error for
…PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.

function Row_Inserted($rsold, &$rsnew)
{
// CODE starts here
//Get Inventry and refrence of stock iD from master table
    $oitemFkey = $rsnew["odInventryFKEY"]; Outbound inventory main key
    $MainFkey = $rsnew["odMInvtryFKEY"]; // Main inventorybook key
    $pdid = $rsnew["oInbProductKey"]; // Main inventroy item table product key
    $arref = $rsnew["odArrivalRefrence"]; //Arrival refrence common for all table
    
    // Submit arrival refrence to oinventoryboo
    $updarref = ExecuteStatement("UPDATE oinventorybook SET oArrivalRefrence='".$arref."' Where OINCID='$oitemFkey'");
    
    //It retrive the field of outbound master table and assign to outbound item table (Code 1-A)
    $omsterID = ExecuteRow("SELECT oRecievedDate, oClientID, oInventryID, oInventryType, oFinancialYear, 
    oDateYear, oDateMonth, oWarehouseID, oEmployeeID  FROM oinventorybook WHERE  OINCID='$oitemFkey'");

    // CODE(1-A) Assign ountbound master inventry to all records in "oinventorybookitems" table
     $ominid = ExecuteStatement("UPDATE oinventrybookitems SET 
     odRecievedDate='".$omsterID["oRecievedDate"]."',
     odClientID='".$omsterID["oClientID"]."',
     odInventryID='".$omsterID["oInventryID"]."', 
     odInventryType = '".$omsterID["oInventryType"]."', 
     odFinancialYear = '".$omsterID["oFinancialYear"]."', 
     odDateYear = '".$omsterID["oDateYear"]."', 
     odDateMonth = '".$omsterID["oDateMonth"]."', 
     odWarehouseID = '".$omsterID["oWarehouseID"]."', 
     odEmployeeID = '".$omsterID["oEmployeeID"]."'
     WHERE odInventryFKEY='$oitemFkey'");

    // CODE(1-B) Get Sum of  all values from oinventorybookitem and send it to oinventorybook in CODE(3)
    // Slect total from oinventorybookitems
     $ogetTotals = ExecuteRow("SELECT 
     SUM(odTotalOutboundCase) AS TotalCaseOutbound, 
     SUM(odTotalOutboundPcs) AS TotalPCSOutbound,
     SUM(odTotaOutboundlFootage) AS TotalFootageOutbound,
     SUM(odTotalOutboundWeight) AS TotalWeightOutbound
     FROM oinventrybookitems WHERE odInventryFKEY='$oitemFkey'");
     // code(2-B) assign values of (1-B)                   
     $addNewtotals = ExecuteStatement("UPDATE oinventorybook SET 
     oTotalOutboundCases='".$ogetTotals["TotalCaseOutbound"]."', 
     oTotalOutboundPcs = '".$ogetTotals["TotalPCSOutbound"]."', 
     oTotalOutboundFootage = '".$ogetTotals["TotalFootageOutbound"]."',
     oTotalOutboundWeight = '".$ogetTotals["TotalWeightOutbound"]."'
     WHERE OINCID='$oitemFkey'");

// CODE(1-4) Update available stcok/inventry in main inventrybookitem table. Minus the outbound stock
// Select values from inventrybookitems
       $getAvailablevalue = ExecuteRow("SELECT
        dAvailablelBalanceOfCasesInStock,
        dAvailableBalanceOfPcsInStock,
        dAvailableBalanceOfFootageInStock,
        dAvailableBalanceOfWeightInStock
        FROM inventrybookitems WHERE  INCDID='$pdid'");

        $uitembalance = ExecuteStatement("UPDATE inventrybookitems SET 
        dAvailablelBalanceOfCasesInStock ='".$getAvailablevalue["dAvailablelBalanceOfCasesInStock"]."' - '".$rsnew["odTotalOutboundCase"]."',
        dAvailableBalanceOfPcsInStock='".$getAvailablevalue["dAvailableBalanceOfPcsInStock"]."' -  '".$rsnew["odTotalOutboundPcs"]."', 
        dAvailableBalanceOfFootageInStock='".$getAvailablevalue["dAvailableBalanceOfFootageInStock"] ."' - '". $rsnew["odTotaOutboundlFootage"]."',
        dAvailableBalanceOfWeightInStock = '".$getAvailablevalue["dAvailableBalanceOfWeightInStock"] ."' - '".  $rsnew["odTotalOutboundWeight"]."', 
        dCurrentStatus = 'In-Service'
        WHERE INCDID='$pdid'");
//  CODE(1-4) ends

// CODE (1-5) Update main inventrybook table values , Outbound and available

            // Select values from inventrybookitems
            $getNewAvailablevalue = ExecuteRow("SELECT
            SUM(dAvailablelBalanceOfCasesInStock) AS NewAvailableCase,
            SUM(dAvailableBalanceOfPcsInStock) AS NewAvailablePcs,
            SUM(dAvailableBalanceOfFootageInStock) AS NewAvailableFootage,
            SUM(dAvailableBalanceOfWeightInStock) AS NewAvailableWt
            FROM inventrybookitems WHERE  dInventryFKEY='$MainFkey'");
            
            // Check if outbound days are less then seven
            // Get current entry date
                $ocdt = $omsterID["oRecievedDate"];
                $daycheck = ExecuteStatement("Select iRecievedDate, iTotalInvoicingWeight from inventorybook 
                where  INCID='$MainFkey'");
                $indt = $daycheck["iRecievedDate"];
                $indate = strtotime($indt);
                $indater = strtotime("+7 day", $indate);
                if($ocdt > $indater) {
                    // Update main inventory values in inventorybook
                    $updbalancemain = ExecuteStatement("UPDATE inventorybook SET 
                    iTotalOutboundCases ='".$ogetTotals["TotalCaseOutbound"]."',
                    iAvailableBalanceOfCases='".$getNewAvailablevalue["NewAvailableCase"]."',
                    iTotalOutboundPcs='". $ogetTotals["TotalPCSOutbound"]."',
                    iAvailableBalanceOfPcs = '".$getNewAvailablevalue["NewAvailablePcs"]."',
                    iTotalOutboundWeight = '".$ogetTotals["TotalWeightOutbound"]."', 
                    iAvailableBalanceOfWeight = '".$getNewAvailablevalue["NewAvailableWt"]."', 
                    iTotalOutboundFootage = '".$ogetTotals["TotalFootageOutbound"]."', 
                    iAvailableBalanceFootage = '".$getNewAvailablevalue["NewAvailableFootage"]."'
                    WHERE INCID='$MainFkey'");
                } else {
                    // Update main inventory values in inventorybook
                    $preCostlesswt = $gettvmain["iTotalCostlessWeight"];
                    $preInvoicewt = $gettvmain["iTotalInvoicingWeight"];
                    $newCostlesswt = $preCostlesswt + $rsnew["odTotalOutboundWeight"];
                    $minusFromInvwt = $preInvoicewt - $newCostlesswt;
                    $updbalancemain = ExecuteStatement("UPDATE inventorybook SET 
                    iTotalOutboundCases ='".$ogetTotals["TotalCaseOutbound"]."',
                    iAvailableBalanceOfCases='".$getNewAvailablevalue["NewAvailableCase"]."',
                    iTotalOutboundPcs='". $ogetTotals["TotalPCSOutbound"]."',
                    iAvailableBalanceOfPcs = '".$getNewAvailablevalue["NewAvailablePcs"]."',
                    iTotalOutboundWeight = '".$ogetTotals["TotalWeightOutbound"]."', 
                    iAvailableBalanceOfWeight = '".$getNewAvailablevalue["NewAvailableWt"]."', 
                    iTotalOutboundFootage = '".$ogetTotals["TotalFootageOutbound"]."', 
                    iAvailableBalanceFootage = '".$getNewAvailablevalue["NewAvailableFootage"]."',
                    iTotalInvoicingWeight = '".$minusFromInvwt."',
                    iTotalCostlessWeight = '".$newCostlesswt."'
                    WHERE INCID='$MainFkey'");
                }

}

$daycheck = ExecuteStatement(“SELECT …”); and $indt = $daycheck[“iRecievedDate”]; is wrong, read Migrating to v2022 → Database Abstraction Layer (DBAL 3).You better check your UPDATE statements before executing them, e.g.

$sql = "UPDATE ....";
Log($sql );
$updbalancemain = ExecuteStatement($sql);

Enable Debug and check the log file for your UPDATE statements and errors. You may also test the UPDATE statements in your database manager to make sure they are correct.

Sir, Thank you very much, I have solved my problem with your suggestions.