mysql_data_seek pdo等效 [英] mysql_data_seek pdo equivalent

查看:54
本文介绍了mysql_data_seek pdo等效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pdo对象相当于mysql_data_seek吗? 你能举个例子吗?

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 (!).

有2种真实的解决方案,

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不支持光标(外部已存储程序),驱动程序无法为您模拟它们".请稍后再试,或者使用MySQL的fork,例如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等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆