title: interactive prompts with proc_open() on psql query
body: <p>I am trying to execute a few PostgreSQL DB commands from a web interface.
  I use proc_open() to pipe to the Windows command prompt.
  Because psql (and all other postgres command) do not accept the password as an option, I must send the password to the write stream.
  The code below causes the browser to hang. Either the resource is not be created, or the password is not being piped properly. Any suggestions are welcome at this point.</p>
  
  <pre><code>$cmd = '""C:\\Program files\\PostgreSQL\\9.0\\bin\\psql.exe" --host localhost --port 5432 -U postgres --dbname $database_name --command "$query""';
  $p=proc_open($cmd, 
               array(array("pipe","r"), array("pipe","w"), array("pipe","w")), 
               $pipes);
  if (is_resource($p)){
    fwrite($pipes[0],"mypassword");
    fclose($pipes[0]);
    proc_terminate($p);
    proc_close($p);                         
  }
  </code></pre>
  
  <p>[You'll notice the crazy double-double-quoting in the command -- this is apparently needed for windows for some reason.]</p>
  
  <p>Work-arounds to this problem are welcome:</p>
  
  <ul>
  <li>I previously tried using system() and exec() but gave up since they don't handle interactive prompt. Is there a better option in php for interactive?</li>
  <li>pg_query() is the main command for interacting with the postgres DB, but pg_dump and pg_restore operations are not supported. Is there another way to backup and restore from binary postgres .backup files that can be accomplished with php?</li>
  </ul>