long ago I wanted to offer new style of access to a database
Example.
old style<?php
# ...
$db = database();
# ...
// Grab the categories sorted by cat_order.
$request = $db->query('', '
SELECT id_cat, cat_order
FROM {db_prefix}categories
ORDER BY cat_order',
array(
)
);
while ($row = $db->fetch_assoc($request))
{
# ...
$cat_order[$row['id_cat']] = $row['cat_order'];
}
$db->free_result($request);
# ...
new style<?php
use Elkarte\DB;
# ...
// Grab the categories sorted by cat_order.
$q = DB::query('
SELECT id_cat, cat_order
FROM {db_prefix}categories
ORDER BY cat_order',
[]
);
while ($row = $q->fetch_assoc) {
# ...
$cat_order[$row['id_cat']] = $row['cat_order'];
}
$q->free;
# ...
DB class here (https://github.com/interlab/cool-db-smf)
If I understand it correctly the use of Closure means PHP > 5.3, right?
it is possible to make on another:
is_callable (...
the main idea in that that was easier to perceive a code (probably I am not right therefore any judgement is interesting to me)
ohhh.. now I think I see what you mean (was paying attention to other details and not the main one).
It is indeed easier to read and I thought about something like that from time to time, dunno about the fact that it has to re-instantiate the class for each and every query, seems a lot of overhead, but code design is not my field, so I don't know.
the class completely isn't completed - there shall be still methods
I simply showed - someone can will want to use it
If someone has ideas - will be glad to look