Subject Re: php.. returning number of rows
Author Fabrice Aeschbacher
Surojit,

ibase_num_fields() does not give the number of records (rows)
returned by a query, but the number of fields (columns).

I would write:

<?php
$dbh = ibase_connect ($host, $username, $password);
$stmt = 'SELECT * FROM tblname';
$sth = ibase_query ($dbh, $stmt);
$record_number = 0

while ($row = ibase_fetch_object ($sth)) {
print $row->email . "\n";
$record_number++;
}
if ($record_number = 0) {
die ("No Results were found for your query");
}

ibase_close ($dbh);
?>

You could also execute another query doing a SELECT COUNT(*), but
this might be slower.

However, this has little to do with IB :-)

HTH,
Fabrice



--- In ib-support@y..., "Surojit Niyogi" <saniyogi@m...> wrote:
> So, PHP natively supports number of fields. And in the manual
shows an example of how this can be used to see whether an empty
results set was returned or not. But I try the example (posted
below) which does NOT seem to work right.
>
> Does anybody know the BEST method of finding out whether the
recordset returned is empty or not? Thanks!
>
> -Surojit
>
>
> <?php
> $dbh = ibase_connect ($host, $username, $password);
> $stmt = 'SELECT * FROM tblname';
> $sth = ibase_query ($dbh, $stmt);
>
> if (ibase_num_fields($sth) > 0) {
> while ($row = ibase_fetch_object ($sth)) {
> print $row->email . "\n";
> }
> } else {
> die ("No Results were found for your query");
> }
>
> ibase_close ($dbh);
> ?>
>
>
>
>
> [Non-text portions of this message have been removed]