Date: 07/01/00
- Next message: Ramy M. Hassan: "[phplib] Calling C functions."
- Previous message: A. Bieri: "[phplib] session4.inc"
- Next in thread: Alexander Aulbach: "Re: [phplib] database abstraction"
- Maybe reply: Alexander Aulbach: "Re: [phplib] database abstraction"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Björn Schotte wrote:
>
> You _should_ write:
>
> $db->query("select count(*) as numrows from bar");
> $db->next_record();
> $numrows = $db->f("numrows");
>
> $db->query("select foo from bar");
> print "We have $numrows rows";
> while ($db->next_record())
> {
> }
>
I agree that num_rows is a bad thing, but I'm concerned that it's
possible to get different results from the two queries (if, for example,
someone else's transaction commits in between). In almost every case
I've found that it works fine to write:
$db->query("select foo from bar");
for ($content="",$numrows=0; $db->next_record(); $numrows++)
{
$content .= "Foo is: " . $db->f("foo") . ".<br>\n";
// etc...
}
print "We have $numrows rows"; // or set_var()
print $content; // or set_var()
This way you're sure that the count will be accurate, and the dbms has
less work to do.
---------------------------------------------------------------------
To unsubscribe, e-mail: phplib-unsubscribe <email protected>
For additional commands, e-mail: phplib-help <email protected>
- Next message: Ramy M. Hassan: "[phplib] Calling C functions."
- Previous message: A. Bieri: "[phplib] session4.inc"
- Next in thread: Alexander Aulbach: "Re: [phplib] database abstraction"
- Maybe reply: Alexander Aulbach: "Re: [phplib] database abstraction"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

