0

I am using this command in wamp, but I am getting empty Mybackup.sql file, did my knows what I am missing?

<?php    exec("pg_dump -U postgres taro-api > Mybackup.sql"); ?>
6
  • How do you authenticate to postgres server? Are you running this code as an unix user, who has the privilege to connect to postgres server as an user postgres? Commented Jan 16, 2019 at 12:49
  • I am executing this through wamp in window machine, please note I am running pg_queries with ease. Commented Jan 16, 2019 at 13:17
  • You command probably causes an error, that's why nothing is written. Commented Jan 16, 2019 at 13:35
  • @Laurenz this is what I am trying to trace. Commented Jan 16, 2019 at 14:56
  • Append 2>&1 to the command, then the error message will be added to the output. That should help. Perhaps pg_dump is not on the PATH. Commented Jan 16, 2019 at 15:38

1 Answer 1

1

With the additional information from the comments, it becomes clear that you are on Windows and pg_dump is not on your PATH.

Either use the full absolute path for pg_dump or add the directory to the PATH environment variable.

Sign up to request clarification or add additional context in comments.

10 Comments

you are helping me alot, can you give me favor that how can I set this? pg_dump is located here, C:\Program Files\PostgreSQL\10\bin, but I want whenever I go live I don't face same issue.
Then use \"C:\\Program Files\\PostgreSQL\\10\\bin\\pg_dump\" -U postgres -d taro-api -f Mybackup.sql.
print_r(exec('\"C:\\Program Files\\PostgreSQL\\10\\bin\\pg_dump\" -U postgres -d taro-api -f 2>&1 Mybackup.sql')); response message "operable program or batch file." this empty .sql is not created as well
If you use single quotesnfor the exec argument, do away with the backslashes escaping the double quotes.
This is the only way to make a logical backup. By the way, you messed up the command. It should be exec('"C:\\Program Files\\PostgreSQL\\10\\bin\\pg_dump" -U postgres -d taro-api -f Mybackup.sql 2>&1').
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.