title: Write postgres output to a file using php
body: <p>I want to get the output of a postgres query written into a file. I am using php to connect to the remote database and execute the query. Here is the sample code.</p>
  
  <pre><code>$connection_id=pg_connect("host=localhost dbname=test user=test password=test");
  $psql="select example from sample limit 180";
  $result=pg_query($connection_id,$psql);
  </code></pre>
  
  <p>I have the query executed, but I am unable to write it to a file. How do I do that? </p>
  
  <p>Help is really appreciated.</p>