phpadvantage-database-server

How to get number of rows with Advantage PHP Extension?


How can I get the number of rows from a SELECT statement result set using the Advantage Database PHP Extension?


Solution

  • I ended up writing my own function that works similar to mysql_num_rows:

    function my_num_rows($result) {
        ob_start(); // begin disable output from ads_result_all
        (int)$number = ads_result_all($result);
        ob_end_clean(); //close and clean the output buffer
        ads_fetch_row($r1, 0); // reset the result set pointer to the beginning
        if ($number >= 0){
             return $number;
        } else {
             return FALSE;
        }
    }
    

    It could also be rewritten to count the rows using ads_fetch_row but this was easier for what I needed. With large result sets there could be slower performance using ads_result_all.