Count number of rows buffered in sqlite result set

后端 未结 4 1510
说谎
说谎 2020-12-22 04:58

I am using count function to get the number of rows buffered in a resultset.

But it always returns count as one even if resultset is empty.

Please see the co

相关标签:
4条回答
  • 2020-12-22 05:18

    As per your comment if you just want to return the count of records you could wrap your query in a SELECT COUNT(*) and change $dbhandle->query to $dbhandle->querySingle. This will work with or without LIMIT.

    $dbhandle = new SQLite3("sqlitedb_111.db");
    $selQuery1 = "SELECT COUNT(*) FROM (SELECT id,dbname,tabname,fieldname FROM scan_results ORDER BY id ASC LIMIT  0,10)";
    $resQuery1 = $dbhandle->querySingle($selQuery1);
    print count($resQuery1);
    
    0 讨论(0)
  • 2020-12-22 05:24

    SQLite is an embedded database, i.e., there is no client/server communication overhead. Therefore, it can return the results dynamically; there is only a single row buffered at any time.

    To get the number of result rows, you either have to step through the results, or execute something like SELECT COUNT(*) FROM (original query).

    0 讨论(0)
  • 2020-12-22 05:35

    Result is an array. find the size of the array.

        $dbhandle = new SQLite3("sqlitedb_111.db");
        $selQuery1 = "SELECT id,dbname,tabname,fieldname FROM scan_results ORDER BY id ASC LIMIT  0,10";
        $resQuery1 = $dbhandle->query($selQuery1);
        $noofrows=sizeof($resQuery1);
        echo $noofrows;
    
    0 讨论(0)
  • 2020-12-22 05:38

    Call numRows() on the result set.

    From http://php.net/manual/en/function.sqlite-num-rows.php

    <?php
    $db = new SQLiteDatabase('mysqlitedb');
    $result = $db->query("SELECT * FROM mytable WHERE name='John Doe'");
    $rows = $result->numRows();
    
    echo "Number of rows: $rows";
    ?>
    
    0 讨论(0)
提交回复
热议问题