In the last post i explained about taking the MySQL backup using php code , This post explains to take the backup of your MySQL database using the passthru function ( passthru documentation )
The passthru() function is similar to the exec() function in that it executes a command. This function should be used in place of exec() or system() when the output from the Unix command is binary data which needs to be passed directly back to the browser
<?php $datestamp = date("Y-m-d"); // Present date to append in the filename for the identification /* CONFIGURE THE FOLLOWING SEVEN VARIABLES TO MATCH YOUR SETUP */ $dbuser = ""; // Database username $dbpwd = ""; // Database password $dbname = ""; // Database name. Use --all-databases if you have more than one $filename= "backup-$datestamp.sql.gz"; // The name (and optionally path) of the dump file $command = "mysqldump -u $dbuser --password=$dbpwd $dbname | gzip > $filename"; $result = passthru($command); ?>
The SQL dump will generate and store in the default directory , You can set the full path in the $filename , Note this will work only in the locally hosted database server
6+ years of experience in building data protection, copy data management and storage management applications, automation software and plugins for private and public clouds
This is a personal weblog. The opinions expressed here represent my own and not those of my employer. my thoughts and opinions change from time to time… This weblog is intended to provide a semi-permanent point in time snapshot and manifestation of the various memes running around my brain, and as such any thoughts and opinions expressed within out-of-date posts may not the same, nor even similar, to those I may hold today.