canyin-project/ybcy/vendor/daoke5/mysqldump/demo.php
2024-11-01 16:07:54 +08:00

32 lines
806 B
PHP

<?php
require_once (__DIR__ . '/vendor/autoload.php');
use EasyMySQLDump\EasyMySQLDump;
use EasyMySQLDump\EasySendEmail;
/**
* 1. Mysqldump
*/
$easyMySQLDump = new EasyMySQLDump();
$easyMySQLDump->setDatabase('127.0.0.1', 3306, 'root', '', 'test')
->setDumpFile('/web/test.mysqldump.sql')
->mysqldump();
/**
* 2. Send email
*/
$easySendEmail = new EasySendEmail();
$easySendEmail->debug = true;
$sendResult = $easySendEmail
->setSubject('mysqldump')
->setBody('A mail to backup mysqldump file')
->setSMTP('smtp.yeah.net', 465, '[username]@yeah.net', '[password]')
->setSender('[sender address]', '[sender name]')
->setReceiver('[receiver address]')
->addAttachment($easyMySQLDump->getDumpFile(), 'mysqldump.sql')
->send();
if ($sendResult === false) {
echo $easySendEmail->error;
exit;
}