Php 在大型数据库中迭代
我已经尝试过将PHP5.3与dbase扩展一起使用,但是对于超过2GB的大型数据库,它不能可靠地工作。我需要一种方法来遍历大型DBF的一个子部分,并能够读取/编辑字段。可以这样做吗(我使用Windows) 第一次尝试:Php 在大型数据库中迭代,php,database,dbf,dbase,Php,Database,Dbf,Dbase,我已经尝试过将PHP5.3与dbase扩展一起使用,但是对于超过2GB的大型数据库,它不能可靠地工作。我需要一种方法来遍历大型DBF的一个子部分,并能够读取/编辑字段。可以这样做吗(我使用Windows) 第一次尝试: table = dbf.Table('myhugeDBF.dbf') #is this the only way to access the dbf data? #I only need the last 10k records as opposed to the whole
table = dbf.Table('myhugeDBF.dbf')
#is this the only way to access the dbf data?
#I only need the last 10k records as opposed to the whole 4.5 GB beast
table.open()
for i in xrange(len(table)-10000, len(table)):
table[i].desc = (table[i].desc).replace("\n","")
print "*" + str(table[i].desc) + "*" #for debug purposes
您是否已锁定到PHP?我有一个应该可以工作(如果不行,我会修复这个bug;)@EthanFurman我在OP中发布了一些示例代码;在您的库中实现这一点的最佳方法是什么?您是否已锁定PHP?我有一个应该可以工作(如果不行,我会修复这个bug;)@EthanFurman我在OP中发布了一些示例代码;在您的库中实现这一点的最佳方法是什么?
table = dbf.Table('myhugeDBF.dbf')
# is this the only way to access the dbf data?
# yes. the above only reads the header, though, so you can get basic
# info about the dbf (size, field names, etc.)
table.open()
# this creates a data structure with one (small) element per record
for record in table[-10000:]:
with record:
record.desc = record.desc.replace('\n','')