rafaelwendel / phpsupabase

PHP Client to use Supabase
MIT License
187 stars 18 forks source link

Count total rows? #7

Closed razvanFrandes closed 1 year ago

razvanFrandes commented 2 years ago

How can I get the total rows count of a table ?

Or a better question is how can I get the headers from a response? I added in the service class $header : count => 'exact', but now I need to access the header response.

Thank you

rafaelwendel commented 2 years ago

Hello razvanFrandes.

I haven't implemented a way to get the headers from the response to a request.

But one way to get the number of rows would be to do a search and then use php count function.


$db = $service->initializeDatabase('products', 'id');

try{
    $listProducts = $db->fetchAll()->getResult(); //fetch all products
    echo "Total: " . count($listProducts) . " rows on product table";
}
catch(Exception $e){
    echo $e->getMessage();
}