[dev] Horde_Db_Adapter count matching records

Sebastian Birnbach birnbacs at gmail.com
Mon Jul 16 07:59:54 UTC 2018


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