1.2.361. Do In Base¶
Use SQL expression to compute aggregates in the database. By doing so, the data don’t have to be transfered from the database to PHP, which saves a lot of operations. Such operations are also often faster in the database, because of optimized code.
<?php
// Efficient way
$res = $db->query('SELECT sum(e) AS sumE FROM table WHERE condition');
// The sum is already done
$row = $res->fetchArray();
$c += $row['sumE'];
// Slow way
$res = $db->query('SELECT e FROM table WHERE condition');
// This aggregates the column e in a slow way
while($row = $res->fetchArray()) {
$c += $row['e'];
}
?>
1.2.361.1. Connex PHP features¶
1.2.361.1.1. Suggestions¶
Rework the query to move the calculations in the database
1.2.361.1.2. Specs¶
Short name |
Performances/DoInBase |
Rulesets |
|
Exakat since |
1.2.8 |
PHP Version |
All |
Severity |
Major |
Time To Fix |
Quick (30 mins) |
Precision |
High |
Available in |