So, annoyingly, the PDO_SQLSRV driver from Microsoft returns -1 on any rowCount() call from a SELECT query with non-scrollable cursors.
Further adding to the annoyance, the default cursor type is _FORWARD, meaning that I am seemingly having to add attributes to every prepared statement where I may need to get a row count back (in this app, that’s A LOT) as below. This is unacceptable, as some of the database engines we will be using do not support scrollable cursors.
$pdo->prepare("SELECT x FROM y", array(PDO::ATTR_CURSOR, PDO::CURSOR_SCROLL));
Curiously this does not seem to work with PDO::query()…
Edit:
As below, I’ve also tried PDO::setAttribute() and adding the option to PDO::__construct(), but neither throw exceptions or errors, or seem to actually do anything!
My question to you all is: is there a way to set the default cursor type to CURSOR_SCROLL?
What about:
?
Also you can extend base PDO class with your own, with
preparemethod overriden: