webERP Forum
DB_num_rows - Printable Version

+- webERP Forum (
+-- Forum: webERP Discussion (/forumdisplay.php?fid=1)
+--- Forum: Development Discussion & Specification (/forumdisplay.php?fid=10)
+--- Thread: DB_num_rows (/showthread.php?tid=2182)

DB_num_rows - serakfalcon - 03-28-2014 05:22 PM

The equivalent of mysqli_num_rows doesn't exist for PDO (or at least, it sort of does, with some drivers, but it's not guaranteed, that's another story).

So, using DB_num_rows() will be inefficient for any driver that doesn't support counting the number of rows.

(I encountered this while working on the Doctrine DBAL layer).

90% of the time, DB_num_rows() is being used to check if there are rows, when the result of DB_fetch_row() / DB_fetch_assoc() / DB_fetch_array() will be === false if there are no rows.

In the code I'm writing I 'cheat' by checking if the result set has columns, which PDO supports, and only count if there are columns, which should avoid a performance hit for most of the times DB_num_rows() is used.

RE: DB_num_rows - phil - 03-29-2014 02:40 PM

Well that's a bit of a nuisance. I guess you could cheat by creating a function DB_num_rows() that tests for the existence of rows and returns 1 if there are some rows. Pretty sure we only use it - although extensively for this. There maybe a couple of exceptions where a work around maybe required.

RE: DB_num_rows - serakfalcon - 03-29-2014 03:40 PM

Just to update that the code in the working copy of webERP that I posted doesn't work as expected, I have a fix for it but the internet is out at my house today (yay developing countries!) Im on my phone right now :/