I'm trying to get some data out of my database from a specific table which currently has 429,000 records.
I'm trying to total up the 'amount' column but running this query is giving me the error of:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes)
Here's my query
$stmt = $db->prepare("SELECT amount FROM salesOrderTransaction WHERE recordStatus=:recordStatus AND paymentStatus=:paymentStatus");
$stmt->bindValue(':recordStatus', '1', PDO::PARAM_STR);
$stmt->bindValue(':paymentStatus', 'Future', PDO::PARAM_STR);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
$total = 0;
foreach ($results as $row) {
$total = $total + $row['amount'];
}
$response['totalTransactionsOwed'] = $total;