mysql_data_seek pdo 等价物

2021-12-26 00:00:00 php mysql pdo

mysql_data_seek 使用 pdo 对象的等价物是什么?可以举个例子吗?

Which is the equivalent of mysql_data_seek using pdo objects? Can you give me an example?

谢谢!

推荐答案

通常的答案是:直接在数组中查找数据 PDOStatement::fetchAll... 但是如果查询获取了大量数据(!).

The usual answer is: do your data seek directly in the array PDOStatement::fetchAll... But it is WRONG IF the query fetches a lot of data (!).

有两个真正的解决方案,

There are 2 real solutions,

1) 如果数据库允许使用 PDO::FETCH_ORI_ABSPDO::FETCH_ORI_REL,例如,

1) if database permits use PDO::FETCH_ORI_ABS or PDO::FETCH_ORI_REL, example,

$result = $sth->fetch(PDO::FETCH_ASSOC, PDO::FETCH_ORI_ABS, 973);

(编辑)但是,正如@ChoiZ 所评论的,有一个 PDO-MySQL 限制:MySQL 不支持cursors"(外部存储程序)并且驱动程序无法为您模拟它们"......稍后尝试或使用 MySQL 的分支,如 MariaDB.

(EDIT) But, as commented by @ChoiZ, have a PDO-MySQL limitation: "MySQL does not support cursors" (outside stored programs) "and the driver cannot emulate them for you"... Try later or with MySQL's forks, like MariaDB.

2) 使用数据库解决方案(一种分页).示例:

2) use the database solution (a kind of pagination). Example:

SELECT a, b FROM table LIMIT 1, 973 

相关文章