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

  • SEARCH
  • Home
  • 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 9318551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:09:24+00:00 2026-06-19T03:09:24+00:00

I want to backup the complete database before having a php script playing around

  • 0

I want to backup the complete database before having a php script playing around with its tables so I thought about using mysqldump.

I tried to run the mysqldump command with shell_exec() and to check if it was successfull like this:

$command = 'mysqldump -u username -ppassword database > /path/database.sql';
$result = shell_exec($command);

if(!is_null($result)) {
  echo 'Error during backup';
else {
  echo 'Database saved';
  // rest of the php script to modify the database (create/drop tables etc)
}

But I noticed that $result is alwas null, even when I give a path where the file cannot be written (no existing directory, or something that should return a permission denied on the shell prompt).

What am I missing?

  • 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-19T03:09:25+00:00Added an answer on June 19, 2026 at 3:09 am

    This worked for me:

    $command = 'mysqldump -u username -ppassword database > /path/database.sql';
    system($command, $output);
    
    if($output != 0) {
      echo 'Error during backup';
    else {
      echo 'Database saved';
      // rest of the php script to modify the database (create/drop tables etc)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a code to backup my Sql Server 2008 Database using
I want to backup my database using mysql dump. This is the code I
I want to take backup or restore of my oracle database through .Net code.
I want to keep backup of my database and import it into different System?
I want to write simple script to copy/backup directory then remove on server startup.
i want to backup firebird database. Below is command that i use to execute
I want to backup a SQL Server database with C#. I have written a
I'm having a couple of websites hosted different places, which I want to backup
I want to backup a particular table with table data from a database in
i just want to ask if how can i backup my database from sql

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.