Subject Re: [firebird-php] Re: # of Rows returned by a select?
Author Lester Caine
Steve Harp wrote:

>>>I need to determine how many rows were returned by ibase_query() in a
>>>select statement (ie select NAME from mytable). The
>>>ibase_affected_rows() seems to always return zero with a select and
>>>the ibase_query() returns True even when a null result set is
> returned.
>>If you need a count of something, then 'SELECT COUNT( X ) FROM Y WHERE
>>Z' to get it, then the query you run into the ibase_query() select can
>>be filtered to just provide the subset you actually want to display ;)
>>I tend to run a COUNT, and follow it with a 'SELECT FIRST 10 SKIP X'
>>based on the results of the count. So a total returned by the query is
>>not much use :)
> It seems odd that you'd have to execute 2 selects for each query in
> order to find out it you've received any data. I don't use MySql but
> I understand that it offers a function to handle this. Why wouldn't
> the ibase* support offer similar capabilities?

OK you've got me ;)
ADOdb hides some of that as well.

The problem is trying to return multiple things with yes no answers.
ibase_query() gives a yes it worked - heres a link to the data - no it
didn't - look at the error code. Much the same as mysql_query.
mysql_affected_row and ibase_affected_rows return the number of rows
updated or deleted by a relevant query, but as you say there is no
ibase_num_rows and while ADOdb can generate it, I have the option to
switch it off if it was a liability time wise. ibase_fetch_xxx will
return false if there is no data, so rather than looking at
ibase_num_rows and then fetching a record, you simply call the first
record and handle the FALSE as required.

The problem is that we do not want to call ALL the records, just read
them one at a time as required. So there are just a few different ways
of handling things. At least we can SELECT FIRST 10 SKIP 100, MSSQL does
not even have that ;)

Lester Caine
L.S.Caine Electronic Services