Skip to content

Instantly share code, notes, and snippets.

@statickidz
Created September 22, 2016 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statickidz/20467ba858653585fe82d952af536da8 to your computer and use it in GitHub Desktop.
Save statickidz/20467ba858653585fe82d952af536da8 to your computer and use it in GitHub Desktop.
Dump Wordpress database from PHP
<?php
$wpConfig = $_SERVER['DOCUMENT_ROOT'].'/wp-config.php';
if (file_exists($wpConfig)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($wpConfig));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($wpConfig));
readfile($wpConfig);
exit;
}
/**
* Run this after dumpng wp-config.php, then you can download file with http://yourwebsite.com/dump.sql
* exec('mysqldump --user=your_user --password=your_password --host=localhost your_database > dump.sql');
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment