title: Copy a PGSQL result Query to a MYSQL Server
body: <p>I need some guidance from you on the best way to do the following:</p>
  <p>I have 2 separate servers:</p>
  <ul>
  <li>Server 1 (Windows): Windows + PGSQL application</li>
  <li>Server 2 (Linux): PHP + MySQL application</li>
  </ul>
  <p>I need to take, with some frequency, the result of a query for from Server 1 to Server 2. This query returns a few thousand results.</p>
  <p>I tried to use the following script in PHP to export the data from PGSQL to CSV and then import it on the MySQL server.</p>
  <pre><code>  $PGcon = pg_connect(&quot;host=$host port=$port dbname=$db user=$user password=$pass&quot;)or die (&quot;Could not connect to server\n&quot;); $MySQLcon = mysqli_connect(&quot;$MySQlHost&quot;, &quot;$MySQLDB&quot;, &quot;$MySQLDBPWD&quot;, &quot;$MySQLDB&quot;) or die (&quot;Could not connect to server\n&quot;); $sql=&quot;COPY (SELECT .... FROM .... WHERE ...) TO '/var/www/html/mycsv.csv' WITH CSV HEADER;&quot; $PGResult = pg_query($con, $sql) or die(&quot;Cannot execute query: $sql\n&quot;);
  </code></pre>
  <p>but I always have the following error:</p>
  <p>Warning: pg_query(): Query failed: ERROR: could not open file &quot;/var/www/html/mycsv.csv&quot; for writing: No such file or directory</p>
  <p>I have already modified the permissions of the mycsv.csv file and changed the owner of the file to the apache user.</p>
  <p>Do you have any idea what it might be? Or do you suggest another approach?</p>