Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8006979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:41:04+00:00 2026-06-04T17:41:04+00:00

I m a begineer in php and having some problem as : I have

  • 0

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 !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T17:41:06+00:00Added an answer on June 4, 2026 at 5:41 pm

    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:

    // notice the file= flag and the piping of error to the file
    $command=
        "/usr/bin/pg_dump --a --no-owner --no-acl --attribute-inserts ".
        "--disable-dollar-quoting --no-tablespaces ".
        "--file={$path['schema_path']}schema-{$latest_update}.sql ".
        "--host={$db['hostname']} --user={$db['username']} ".
        "--password --port={$db['port']} {$db['database']} > pg_dump_error.log 2>&1"; 
    
    // no output to capture so no need to store it
    passthru($command);
    
    // read the file, if empty all's well
    $error = file_get_contents('pg_dump_error.log');
    if(trim($error) != '')
        exit("PG_DUMP ERRROR:\n-----\n$error\n");
    

    Hope this is more or less what you were looking for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm a beginner to php. i need to use php function which process some
I'm a beginner at PHP. I'm using Zend AMF which is used for RPCs.
I'm having some trouble trying to get my script to send a file attachment
I have a form and php processing file, and everything seems to be working
I'm having a form in a .erb file, where the user can enter some
I am a PHP beginner. I have developed a social networking website similar to
I am beginner in PHP. I am trying to parse this xml file. <relationship>
EDIT: The plugin in question is located here . PHP beginner here using a
Beginner help needed :) I am doign an example form a php book which
I'm a beginner at PHP, and I'm still trying to work out proper file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.