in reply to Re: Right Number DB
in thread Right Number DB

You could do it in two steps -

Step 1 Explicitly get the row count with SQL -
SELECT count(*) FROM table where ...
And then retrieve the rowcount from the query result.

Step 2 Prepare the actual SQL to fetch the data. Since you already know the row count from the previous step, you can easily implement the required logic.

$sth = $dbh->prepare($sql); $sth->execute(); if ($rowcount == 1) { # do single row logic # fetch data } else { # do multi-row logic # fetch data with while loop }
There is a rowcount variable in the DBI, but I would not rely on it because it is not reliable (and database dependent?).