1

I am using PHRets to fetch mls data. But it is fetching nothing. I am fetching data from MLXchange site. I used the Retsconnector(Desktop application) and its fetching data. I used same query in PHRets but it is not working.

Here below is my code. Please help me.

            <?
            $rets_modtimestamp_field = "80";


            $property_classes = array("4");


            $previous_start_time = "1980-01-01T00:00:00";

            //////////////////////////////

            require_once("phrets.php");

            // start rets connection
            $rets = new phRETS;

            $rets->AddHeader("User-Agent", "RETS-Connector/1.2");

            // only enable this if you know the server supports the optional RETS feature called 'Offset'
            $rets->SetParam("offset_support", true);

            echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
            $connect = $rets->Connect($rets_login_url, $rets_username, $rets_password,$user_agent_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+");

                    $fields_order = array();

                    $query = "({$rets_modtimestamp_field}={$previous_start_time}+)";

                    // run RETS search
                    echo "   + Resource: Property   Class: {$class}   Query: {$query}<br>\n";
                    $search = $rets->SearchQuery("Property", $class, $query, array('Limit' => 1000));

                    if ($rets->NumRows($search) > 0) {

                            // 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);
                            }

                    }

                    echo "    + Total found: {$rets->TotalRecordsFound($search)}<br>\n";

                    $rets->FreeResult($search);

                    fclose($fh);

                    echo "  - done<br>\n";

            }

            echo "+ Disconnecting<br>\n";
            $rets->Disconnect();
Binod Kalathil
  • 1,939
  • 1
  • 30
  • 43
  • 1
    Are you setting "RETS-Version"? and also are you sure that "1980-01-01T00:00:00" is the expected format? or in this format "1980-01-01 00:00:00". can you post the output? – V-T Aug 12 '14 at 07:51
  • Yeah, be sure to set your Rets version. – Jeremy Jackson May 06 '15 at 19:58
  • Are you certain you can query back that far AND that the server has offset built in? Have you tried removing offset? – Petrogad May 29 '15 at 19:48

1 Answers1

0

To this specific question you are using class(2nd parameter) as "4". Probably this is wrong.

To all those who end up here like me,

Since same query is having results in "MLXchange" site, we have below things to check in this line: $search = $rets->SearchQuery("Property", $class, $query, array('Limit' => 1000));

  1. The value of Resource(1st parameter)
  2. The value of Class(2nd parameter)

Values of these parameters also varies with various MLS'

Binod Kalathil
  • 1,939
  • 1
  • 30
  • 43