|
Posted by Toby A Inkster on 04/03/07 11:24
Jerry Stuckle wrote:
> Simon Stienen wrote:
>> On 2007-04-03 04-52-47, Jerry Stuckle wrote:
>>
>>> Not at all a bad design. Any class will do the same thing. It
>>> handles a single query. If you make another query, that will
>>> overwrite the original query. If you want two concurrent queries,
>>> you use two db objects.
>>
>> One query per _DATABASE_? Sorry, but I think this is a somewhat
>> limited approach.
>
> No, the DB object represents a QUERY. You can have one QUERY open
> at a time. This is pretty standard for objects - each
> instantiation handles a specific object.
The normal way that database objects seem to operate in PHP is that one
database object can handle multiple concurrent queries by returning a
"ResultSet" type element for each query, such that the ResultSet can be
assigned to a variable and used at a later date, and the main database
object can be used for other queries in the meantime.
That is, they do not do:
$db1->query("SELECT ...");
$db2->query("SELECT ...");
$rows[] = $db1->fetch();
$more[] = $db2->fetch();
which requires two (usually heavyweight) database objects, but instead do:
$resultset1 = $db->query("SELECT ...");
$resultset2 = $db->query("SELECT ...");
$rows[] = $resultset1->fetch();
$more[] = $resultset2->fetch();
which only requires one database object.
Examples of the kind of behaviour Simon's describing include the mysqli
extension's "query" method, PDO's "query" method, and PEAR package DB. The
same principles, though using a slightly odd syntax can be found in PEAR's
MDB package:
$resultset1 = $db->query("SELECT ...");
$resultset2 = $db->query("SELECT ...");
$rows[] = $db->fetchInto($resultset1);
$more[] = $db->fetchInto($resultset2);
Again the same principle can be seen in most of the older non-OO database
interfaces, though (obviously) using a less object-oriented syntax:
$resultset1 = dbx_query($db, "SELECT ...");
$resultset2 = dbx_query($db, "SELECT ...");
$rows[] = dbx_fetch_row($resultset1);
$more[] = dbx_fetch_row($resultset2);
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|