4

For instance, I have a table with two fields: id, value. I've inserted almost 100k rows in this table.

I want to use scrollable cursor. I wrote the following code:

<?php
...
$sql = 'SELECT id FROM cursor_test;';
$stmt = $dbh->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL));
$stmt->execute();

$row = $stmt->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, 3);
var_dump($row['id']); // 1, expected value is 3

What am I doing wrong?

Igor Timoshenko
  • 1,001
  • 3
  • 14
  • 27

1 Answers1

3

Seems that mysql does not support scrollable cursors.

https://bugs.php.net/bug.php?id=34625

http://www.php.net/manual/en/pdostatement.fetch.php#105277

Will PDO laststatment->fetchAll(PDO::FETCH_COLUMN, $column) rerun the query each call?

Community
  • 1
  • 1
egemadra
  • 43
  • 1
  • 5
  • Perhaps, but this bug was reported in 2005. How about MySQLi extension? I saw there functions to set seek... Do you know anything about it? – Igor Timoshenko Aug 22 '12 at 08:38
  • I used to use mysql extension (not mysqli) and it also had seek functions. Honestly I don't know how it works but I'm haven't found anything on the net that provides a similar function in PDO but just workarounds like fetching all results. – egemadra Aug 30 '12 at 00:36
  • @egemadra The `data_seek()` function of mysql fetches all rows. It looks like a cursor, but it ain't. – djot Sep 29 '13 at 09:49