title: PHP To Retrieve PostGIS Geography Types
body: <p>I have a PostGIS database with a geography column.  I'd like to be able to use PHP to SELECT the geography so then I could run another query using ST_Distance to get the distance between the points.  However, when I run </p>
  
  <pre><code>SELECT geog from locations;
  </code></pre>
  
  <p>I get a weird value of 6 instead of the HEX output (something like 0101000020E6100000C442AD69DEAD5740575BB1BFEC6E3D40 is what I'm expecting).  When I use the same query in phpPgAdmin I get the expected output, but not from my PHP script :(</p>
  
  <p>I'd really appreciate any help :)</p>
  
  <p>Thank you,</p>
  
  <p>elshae</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>$locations_result = @pg_query($DBConnect, "SELECT geog from locations;");
  
      if (!$locations_result) {
          echo "An error occurred upon getting data from the locations table.\n";
          exit;
      }
      $i = 0;
      while ($locations_arr = pg_fetch_row($locations_result)) {
  
          $locations['location'][$i] = $locations_arr[0];
  
                  echo $locations['location'][$i];
          $i++;
      }
  </code></pre>
  
  <p><strong>EDIT2</strong>
  So now I am trying to select the geography right into the ST_Distance function so that it can just get the geography result directly, something like:</p>
  
  <pre><code>SELECT ST_Distance(geog_a, geog_b) FROM(SELECT geog AS geog_a FROM location WHERE id=123 UNION SELECT geog AS geog_b FROM location WHERE id=345);
  </code></pre>
  
  <p>But my SQL syntax is wrong and I have yet to figure out how I can get the result I'm aiming for.  The UNION is putting these values into one column, which is what I have already.  Instead I need something like:</p>
  
  <pre><code>geog_a |geog_b
  ----------------
  hdsklgh|shfksh
  </code></pre>