問題描述
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_ABS
或 PDO::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
這篇關于mysql_data_seek pdo 等價物的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!