I m a begineer in php and having some problem as :
I have a php file having a function create_dump() in which I am dumping my postgresql database using pg_dump command.
Now while executing php file from linux terminal it asks for postgresql password on terminal.
I want to add error handling in my php file if user provides wrong password for the database unintentionally.
In other words :
How to catch pg_dump (postgresql command) execution error from my php file ?
Thanks !
Based on the info you provided I have a workaround for what you want to do. First, instead of piping the output of your dump using the ‘>’ you will need to use the –file=some_file.sql flag instead which does the same job.
Now, it does not appear that the $output from the passthru call will capture the output even if you send stderr to stdout so here’s what would work. You would modify the command using the –file= flag and pipe the output of the command (which contains the error) to a log file while making sure to also send stderr to stdout (do 2>&1 after the command) in order to capture the error.
Here’s the code:
Hope this is more or less what you were looking for.