因此,我有一个来自Paragon的RETS数据提要,我试图使用phRETS库将所有这些数据转储到CSV中。我尝试过许多不同的方法,通过dmql或libRETS从这个RETS提要中转储数据,但它们都没有起作用。下面是我的php代码,它使用phRETS来尝试转储数据提要。
现在它只生成一个空的csv。这就是终端中显示的内容。
- Connected
- Query: (LIST\_87=1980-01-01T00:00:00+) Limit: 1000 Offset: 0- Total found: 0- done
我不会在这里包含RETS提要的正确的url,但是它使用的是版本1.5
<?php
$rets_login_url = "http://Insert RETS feed link /login?rets-version=rets/1.5";
$rets_username = "**************";
$rets_password = "**********";
// use http://retsmd.com to help determine the SystemName of the DateTime field which
// designates when a record was last modified
$rets_modtimestamp_field = "LIST_87";
// use http://retsmd.com to help determine the names of the classes you want to pull.
// these might be something like RE_1, RES, RESI, 1, etc.
$property_classes = array("RE_1");
// DateTime which is used to determine how far back to retrieve records.
// using a really old date so we can get everything
$previous_start_time = "1980-01-01T00:00:00";
//////////////////////////////
require_once("phrets.php");
// start rets connection
$rets = new phRETS;
echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password);
if ($connect) {
echo " + Connected<br>\n";
}
else {
echo " + Not connected:<br>\n";
print_r($rets->Error());
exit;
}
foreach ($property_classes as $class) {
echo "+ Property:{$class}<br>\n";
$file_name = strtolower("property_{$class}.csv");
$fh = fopen($file_name, "w+");
$maxrows = true;
$offset = 0;
$limit = 1000;
$fields_order = array();
while ($maxrows) {
$query = "({$rets_modtimestamp_field}={$previous_start_time}+)";
// run RETS search
echo " + Query: {$query} Limit: {$limit} Offset: {$offset}<br>\n";
$search = $rets->SearchQuery("Property", $class, $query, array('Limit' => $limit, 'Offset' => $offset, 'Format' => 'COMPACT-DECODED', 'Count' => 1));
if ($rets->NumRows() > 0) {
if ($offset == 1) {
// print filename headers as first line
$fields_order = $rets->SearchGetFields($search);
fputcsv($fh, $fields_order);
}
// process results
while ($record = $rets->FetchRow($search)) {
$this_record = array();
foreach ($fields_order as $fo) {
$this_record[] = $record[$fo];
}
fputcsv($fh, $this_record);
}
$offset = ($offset + $rets->NumRows());
}
$maxrows = $rets->IsMaxrowsReached();
echo " + Total found: {$rets->TotalRecordsFound()}<br>\n";
$rets->FreeResult($search);
}
fclose($fh);
echo " - done<br>\n";
}
echo "+ Disconnecting<br>\n";
$rets->Disconnect();问题的一部分是,这一行代码出错了。
require_once("phrets.php");
我没有这个文件,所以我搜索了它并从https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php找到了一个https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php文件。
这可能是那个文件的坏版本,但我不知道。
如果有人知道如何在RETS提要上执行数据转储,请告诉我。如果有比使用phRETS更好的方法,那么请告诉我。我只需要将RETS提要中的数据转储到csv或其他东西中。谢谢!
编辑:我将我的LIST_87更改为L_UPDATEDATE,它现在正在查找数据,但没有将其写入文件。我也把限制改为200。这是我的终端现在显示的内容。
- Property:RE\_1- Query: (L\_UPDATEDATE=1980-01-01T00:00:00+) Limit: 200 Offset: 0- Total found: 1193- Query: (L\_UPDATEDATE=1980-01-01T00:00:00+) Limit: 200 Offset: 200- Total found: 1193- Query: (L\_UPDATEDATE=1980-01-01T00:00:00+) Limit: 200 Offset: 400- Total found: 1193- Query: (L\_UPDATEDATE=1980-01-01T00:00:00+) Limit: 200 Offset: 600- Total found: 1193- Query: (L\_UPDATEDATE=1980-01-01T00:00:00+) Limit: 200 Offset: 800- Total found: 1193- Query: (L\_UPDATEDATE=1980-01-01T00:00:00+) Limit: 200 Offset: 1000- Total found: 1193- done- Disconnecting
我创建的csv文件中仍然只有一个空表。
发布于 2017-07-13 03:49:29
发布于 2017-12-13 07:22:05
在代码中,需要将$offset的初始值更改为1。
$offset = 1;由于$offset的值为0,因此以下条件失败,
if ($offset == 1) {
// print filename headers as first line
$fields_order = $rets->SearchGetFields($search);
fputcsv($fh, $fields_order);
}没有写入CSV的头,$fields_order数组仍然是空的。
然后是while循环,
foreach ($fields_order as $fo) {
$this_record[] = $record[$fo];
}$this_record仍然是空的,因为$fields_order数组是空的。
因此,即使存在数据,CSV也会变为空的。
https://stackoverflow.com/questions/45067412
复制相似问题