title: Dumping a RETS Data Feed
body: <p>So I have a RETS data feed from Paragon I am trying to dump all this data into a CSV using phRETS library. I have tried many different ways to dump data from this RETS feed via dmql or libRETS and none of them are working. Here is my php code using phRETS to try to dump the data feed.</p>
  
  <p>Right now it just generates an empty csv. This is what is displayed in the terminal.</p>
  
  <ul>
  <li>Connecting to <a href="http://RETS" rel="nofollow noreferrer">http://RETS</a> url here/login?rets-version=rets/1.5 as user<br>
  
  <ul>
  <li>Connected<br></li>
  </ul></li>
  <li>Property:RE_1<br>
  
  <ul>
  <li>Query: (LIST_87=1980-01-01T00:00:00+)  Limit: 1000  Offset: 0<br></li>
  <li>Total found: 0<br></li>
  <li>done<br></li>
  </ul></li>
  <li>Disconnecting<br></li>
  </ul>
  
  <p>I wont include the correct url to the RETS feed in here but it is using version 1.5</p>
  
  <pre><code> &lt;?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}&lt;br&gt;\n";
  $connect = $rets-&gt;Connect($rets_login_url, $rets_username, $rets_password);
  
  if ($connect) {
          echo "  + Connected&lt;br&gt;\n";
  }
  else {
          echo "  + Not connected:&lt;br&gt;\n";
          print_r($rets-&gt;Error());
          exit;
  }
  
  foreach ($property_classes as $class) {
  
          echo "+ Property:{$class}&lt;br&gt;\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}&lt;br&gt;\n";
                  $search = $rets-&gt;SearchQuery("Property", $class, $query, array('Limit' =&gt; $limit, 'Offset' =&gt; $offset, 'Format' =&gt; 'COMPACT-DECODED', 'Count' =&gt; 1));
  
                  if ($rets-&gt;NumRows() &gt; 0) {
  
                          if ($offset == 1) {
                                  // print filename headers as first line
                                  $fields_order = $rets-&gt;SearchGetFields($search);
                                  fputcsv($fh, $fields_order);
                          }
  
                          // process results
                          while ($record = $rets-&gt;FetchRow($search)) {
                                  $this_record = array();
                                  foreach ($fields_order as $fo) {
                                          $this_record[] = $record[$fo];
                                  }
                                  fputcsv($fh, $this_record);
                          }
  
                          $offset = ($offset + $rets-&gt;NumRows());
  
                  }
  
                  $maxrows = $rets-&gt;IsMaxrowsReached();
                  echo "    + Total found: {$rets-&gt;TotalRecordsFound()}&lt;br&gt;\n";
  
                  $rets-&gt;FreeResult($search);
          }
  
          fclose($fh);
  
          echo "  - done&lt;br&gt;\n";
  
  }
  
  echo "+ Disconnecting&lt;br&gt;\n";
  $rets-&gt;Disconnect();
  </code></pre>
  
  <p>Part of the issue was I was getting an error for this line of code </p>
  
  <p>require_once("phrets.php");</p>
  
  <p>I did not have this file so I googled it and found a phrets.php file from <a href="https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php" rel="nofollow noreferrer">https://github.com/dangodev/PHRETS-Example/blob/master/lib/phrets.php</a></p>
  
  <p>This could be a bad version of that file but I do not know. </p>
  
  <p>If anyone knows how to perform a data dump on a RETS feed then please let me know. If there is a better way than using phRETS then let me know. I really just need to dump the data from my RETS feed into a csv or into something. Thanks!</p>
  
  <p>EDIT: I changed my LIST_87 to L_UPDATEDATE and it is now finding data but not writing it to file. I also changed the Limit to 200. Here is what my terminal is displaying now.</p>
  
  <ul>
  <li>Connected<br>
  
  <ul>
  <li>Property:RE_1<br></li>
  <li>Query: (L_UPDATEDATE=1980-01-01T00:00:00+)  Limit: 200  Offset: 0<br></li>
  <li>Total found: 1193<br></li>
  <li>Query: (L_UPDATEDATE=1980-01-01T00:00:00+)  Limit: 200  Offset: 200<br></li>
  <li>Total found: 1193<br></li>
  <li>Query: (L_UPDATEDATE=1980-01-01T00:00:00+)  Limit: 200  Offset: 400<br></li>
  <li>Total found: 1193<br></li>
  <li>Query: (L_UPDATEDATE=1980-01-01T00:00:00+)  Limit: 200  Offset: 600<br></li>
  <li>Total found: 1193<br></li>
  <li>Query: (L_UPDATEDATE=1980-01-01T00:00:00+)  Limit: 200  Offset: 800<br></li>
  <li>Total found: 1193<br></li>
  <li>Query: (L_UPDATEDATE=1980-01-01T00:00:00+)  Limit: 200  Offset: 1000<br></li>
  <li>Total found: 1193<br></li>
  <li>done<br></li>
  <li>Disconnecting<br></li>
  </ul></li>
  </ul>
  
  <p>my csv file that is created still just has an empty table in it.</p>