Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DB_num_rows
03-28-2014, 05:22 PM,
#1
DB_num_rows
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.
Reply
03-29-2014, 02:40 PM,
#2
RE: DB_num_rows
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.
Phil Daintree
webERP Admin
Logic Works Ltd
http://www.logicworks.co.nz
Reply
03-29-2014, 03:40 PM,
#3
RE: DB_num_rows
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 :/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)