in what is efficient to execute multiple queries:
nextRowset() function to move over the queries
$stmt = $db->query("SELECT 1; SELECT 2;"); $info1 = $stmt->fetchAll(); $stmt->nextRowset(); $info2 = $stmt->fetchAll();
or multiple executions plan which is a lot easier to manage?
$info1 = $db->query("SELECT 1;")->fetchAll(); $info2 = $db->query("SELECT 2;")->fetchAll();
Performance of the code is likely to be similar.
The code at the bottom, to me, is more efficient for your software design because:
- it is more readable
- it can be changed with less chance of error since each of them addresses 1 query only
- individual query and its interaction can be moved to a different function easily and can be tested individually
That’s why I feel that overall efficiency (not just how fast data comes back from DB to PHP to the user, but also maintainability/refactoring of code) will be better with the code at the bottom.