Charlotte Rets

45 views
Skip to first unread message

Rez3366

unread,
Feb 19, 2012, 1:29:40 PM2/19/12
to PHRETS
Hi,
Need some help pulling data back from the Charlotte Rets server. I
am connectiing successfully but no data is being pulled back. Have
tried various code mods to the example code from the phrets site but
nothing is pulling back. I realize that this may require someone that
has experience with the Charlotte Rets server although it could be
something generic that I am missing. The code below is what I am using
currently obviously with username and password removed .

<?php

$rets_login_url = "http://cmls.retsiq.com/contact/rets/login";
$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 = "LastTransDate";
//$rets_modtimestamp_field = "ListDate";

// 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("2","3","4");

// 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 = "1990-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 = 1;
$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));
//$search = $rets->SearchQuery("Property", $class,
$query, $fields);

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";

}
Reply all
Reply to author
Forward
0 new messages