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?

0

1 Answer 1

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?

3
  • 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? Aug 22, 2012 at 8: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, 2012 at 0:36
  • @egemadra The data_seek() function of mysql fetches all rows. It looks like a cursor, but it ain't.
    – djot
    Sep 29, 2013 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.