I have the following work flow which I'd like to automate with short PHP script.
- Download gzfile (with db dump) from specific URL (potentially FTP).
- Decode the file to txt.
- Import the txt to local postgre with psql (using cmd).
Now I have 2 questions:
- What is the best way to pass the gunzipped file to pg_query?
- I get an er开发者_运维问答ror when PHP reaches this line:
COPY rf (datum, id_emailu_op, recency, frequency) FROM stdin; 2011-08-29 8484 3 1
. Can the stdin be a problem?
Thank you all!
A pg_dump file is meant to be imported via psql. You can load the file contents in, and even decompress it with php, then open a pipe to psql writing data out to that process (assuming you are on a unix machine). When psql is executed in this way as far as it's concerned the data you're writing via your php script is coming in via stdin.
精彩评论