php mysql 游标
我需要创建一个 MySQL 游标来跟踪我在遍历“巨大”(数百万个整体)表时当前所处的行号。
示例数据库表:
CREATE TABLE test (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
someText TEenter code hereXT NOT NULL
) ;
如果该表有 1,000,000 个条目;我执行以下查询:
select * from test where id >= 50;
然后我根据需要在 php 脚本中处理数据(限制为 1 分钟)。我如何跟踪我已经遍历“测试”表的哪一行?
I need to create a MySQL cursor to keep track of what row number I am currently up to while traversing a "huge"(millions of entires) table.
sample database table:
CREATE TABLE test (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
someText TEenter code hereXT NOT NULL
) ;
if this table as 1,000,000 entries; I execute the following query:
select * from test where id >= 50;
And then I process the data as needed in my php script (with 1 min limit). How do i keep track of up to what row I have traversed "test" table?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我只能按照你告诉我的去做,尽管我觉得这应该本地受到限制,而不仅仅是等待 PHP 超时。
编辑另一种扩展批处理思想的方法是更改表并添加可以更新的“已处理”列。
EDIT2 另外,要小心。我确实设置/取消设置会话值。因此,如果您刷新,即使页面加载成功而不是超时错误,也可能会陷入无限循环($lastID 不会看到会话变量,它将再次从 1 开始,然后继续执行再次)。
I can only go by what you're telling me, though I feel this should be natively throttled, not just awaiting PHP to spit out a timeout.
EDIT Another method, extending the batch idea, is to ALTER the table and add a "processed" column you can update.
EDIT2 Also, be careful. I do set/unset the session value. For that reason, this could go infinite loop on you if you refresh even though you got a successful page load back instead of a timeout error (the $lastID won't see a session variable, it will start again at 1, and proceed through again).