I've build a mechanism to format query results as an array with a specific pattern. For example :
<?php
// Pattern
$aPattern = array(
'cust_id' => array(
'@detail' => array(
'@name' => '%{forename} {name}',
'@company' => 'company'
),
'@orders_total' =>
array('article' => 'qty')
)
);
// Query
$sQuery = "SELECT `cust`.*, `order`.`article`, SUM(`quantity`) AS qty
FROM `cust` LEFT JOIN `order` ON `cust`.`id` = `order`.`cust_id`
GROUP BY `cust`.`id`, `order`.`article`";
// Run query and set fetch mode
$oStatement = Data::query($sQuery)->setFetchPattern($aPattern);
// Fetch results
$aRes = $oStatement->fetchAll();
It works fine, but when formatting lots of rows (> 5000) it takes too much time. I've been looking for existing solutions that could do the job more efficiently without success. Before posting code to ask if anyone can help me to improve it, do someone know if there is a PHP class or something like that which already performs this kind of work ?
Thanks in advance, and sorry for any StackOverflow misuse