[dev] Horde_Db_Adapter count matching records

Sebastian Birnbach birnbacs at gmail.com
Mon Jul 16 09:16:09 UTC 2018


SOLVED, please disregard previous mail.

For the archives: COUNT() is a SQL function; for calling there must not be
a space before the brackets:
COUNT(*) <-- OK
COUNT (*) <-- NOK

  birnbacs

2018-07-16 9:59 GMT+02:00 Sebastian Birnbach <birnbacs at gmail.com>:

> All,
>
> I am using Horde_Db_Adapter for querying a mySQL database; driver is
> mysqli. I need to get the number of results for a query in order to display
> them pagewise.
>
> $adapter = $injector->getInstance('Horde_Db_Adapter');
> $query = "SELECT (*) FROM my_table WHERE variable = condition";
> $res = $adapter->select($query);
> $numres = iterator_count($res);
>
>
> If results are plenty, retrieving all of them may put a huge load on the
> webserver, so I tried database counting:
>
> $query = "SELECT COUNT (my_table.variable) AS myvar FROM my_table WHERE
> variable = condition";
>
> but  wthout luck:
>
> QUERY FAILED: FUNCTION horde.COUNT does not exist.
>
>
> Question: is there a way of determining, with the Horde DB adapter, how
> many records match a given query without actually retrieving the records?
>
>
> Thanks
>
>   birnbacs
>


More information about the dev mailing list