How can I do a DB Dump with PHP/Pear?

Hello there,

I need to do a DB dump for a website, but its using code I’m not familiar with can anyone help?

Here is the connection information:


require_once 'DB/DataObject.php'; <<-- cant see this file

$options = &PEAR::getStaticProperty('DB_DataObject','options');
$options = array(
        'database'   => 'mysql://MYWEBSITE_web:manse1802@localhost/MYWEBSITE_web',
        'schema_location'  => '/home/MYWEBSITE/DataObjects',
        'class_location'   => '/home/MYWEBSITE/DataObjects',
        'require_prefix'   => 'DataObjects/',
       'class_prefix'     => 'DataObjects_',
        );


Now obviously not being completely useless I normally use this script to to a DB and email it to me, but in this case I just get a bank file. The lack of a password could the problem?


// mysql & minor details..
$tmpDir = "/tmp/";
$user = "manse1802";
$password = "";
$dbName = "MYWEBSITE_web";
$prefix = "DataObjects_";

// email settings...
$to = "me@xxx.com";
$from = "noreply@xxx.com";
$subject = "db - backup";
$sqlFile = $tmpDir.$prefix.date('Y_m_d').".sql";
$attachment = $tmpDir.$prefix.date('Y_m_d').".tgz";

$creatBackup = "mysqldump -u ".$user." --password=".$password." ".$dbName." > ".$sqlFile;
$createZip = "tar cvzf $attachment $sqlFile";
exec($creatBackup);
exec($createZip);

$headers = array('From' => $from, 'Subject' => $subject);
$textMessage = $attachment;
$htmlMessage = "";

$mime = new Mail_Mime("\
");
$mime->setTxtBody($textMessage);
$mime->setHtmlBody($htmlMessage);
$mime->addAttachment($attachment, 'text/plain');
$body = $mime->get();
$hdrs = $mime->headers($headers);
$mail = &Mail::factory('mail');
$mail->send($to, $hdrs, $body);

unlink($sqlFile);
unlink($attachment);


I am completely noob in this field and really trying to learn these things. Can you tell me what is dumping means here?

Take a complete copy of the database irelivent of what tables are setup within the database and put it into a text/sql file so the information can be impotred into a new database or used to restore the current database at some point.

This is a pretty good guide to get you started with databases dumping: Dumping & Restoring MySQL | UK Web Hosting