예제 #1
0
 * This file contains the Backup_Database class wich performs
 * a partial or complete backup of any given MySQL database
 * @author Daniel López Azaña <http://www.daniloaz.com>
 * @version 1.0
 * http://www.daniloaz.com/en/560/programming/backup-de-bases-de-datos-mysql-con-php/
 */
/**
 * Define database parameters here
 */
define("OUTPUT_DIR", '../unused/sqldmp');
define("TABLES", '*');
/**
 * Instantiate Backup_Database and perform backup
 */
$backupDatabase = new Backup_Database(SERVER, USERNAME, PASSWORD, DATABASE);
$status = $backupDatabase->backupTables(TABLES, OUTPUT_DIR) ? 'OK' : 'KO';
echo "<br /><br /><br />Backup result: " . $status;
/**
 * The Backup_Database class
 */
class Backup_Database
{
    /**
     * Host where database is located
     */
    var $host = '';
    /**
     * Username used to connect to database
     */
    var $username = '';
    /**
예제 #2
0
<?php

require_once './conexion.php';
$usuario = 'root';
$password = '';
$db = 'db_farmacia';
$local = 'localhost';
$tables = '*';
$dir = 'd:backup';
/**
 * Instantiate Backup_Database and perform backup
 */
$backupDatabase = new Backup_Database($local, $usuario, $password, $db);
$status = $backupDatabase->backupTables($tables, $dir) ? 'OK' : 'KO';
echo "\n\n\nBackup result: " . $status;
/**
 * The Backup_Database class
 */
class Backup_Database
{
    /**
     * Host where database is located
     */
    var $host = '';
    /**
     * Username used to connect to database
     */
    var $username = '';
    /**
     * Password used to connect to database
     */
예제 #3
0
        protected function saveFile(&$sql, $outputDir = '.')
        {
            if (!$sql) {
                return false;
            }
            try {
                $handle = fopen($outputDir . '/' . $this->dbName . '-' . date("dmY-His") . '.sql', 'w+');
                fwrite($handle, $sql);
                fclose($handle);
            } catch (Exception $e) {
                var_dump($e->getMessage());
                return false;
            }
            return true;
        }
    }
    /**
     * Instantiate Backup_Database and perform backup
     */
    $backupDatabase = new Backup_Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
    $status = $backupDatabase->backupTables(TABLES, OUTPUT_DIR) ? 'Conclu&iacute;do' : 'ERRO';
    echo "\n<hr/><p>\nBackup " . $status . '!';
    echo '<p>Salvo em : <b>' . OUTPUT_DIR . '</b></p>';
    echo '<br/>';
    echo '<a href="principal.php" class="btn btn-success">Voltar</a>';
} else {
    header('Location: principal.php');
}
if ($_SESSION["logado"] == false) {
    header('Location: logout.php');
}
예제 #4
0
$sendMailer->AddAddress('*****@*****.**');
//$sendMailer->AddAddress('*****@*****.**');
$sendMailer->Subject = "Daily Sales Email Report";
$sendMailer->IsHTML(true);
$sendMailer->Body = date('d/m/Y H:i:s') . "\n<table border='0'>\n<tr>\n\t<td>Daily  </td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['d']}</td>\n</tr>\n<tr>\n\t<td>Weekly </td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['w']}</td>\n</tr>\n<tr>\n\t<td>Monthly</td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['m']}</td>\n</tr>\n<tr>\n\t<td>Yearly </td><td>:</td><td style='font-family:courier new; text-align:right;'>{$sales['y']}</td>\n</tr>\n</table>";
$result['mailsales'] = 'sending';
try {
    $sent = $sendMailer->Send();
    if ($sent) {
        $result['mailsales'] = 'sending success';
        $result['text'] .= ' sales figure sent.';
    } else {
        $result['mailsales'] = 'sending failed';
    }
} catch (phpmailerException $e) {
    $result['mailsales'] = $e->errorMessage();
} catch (Exception $e) {
    $result['mailsales'] = $e->getMessage();
}
if (!$result['exists']) {
    include 'mysql-backup.php';
    $dbbackup = new Backup_Database($server, $user, $pass, $db, 'utf-8');
    $status = $dbbackup->backupTables('*', 'localhost', $backupname, $log);
    $result['result'] = $status;
} else {
    $result['result'] = false;
}
if (!$log) {
    header('Content-type: application/json');
}
echo json_encode($result);
<?php

define("DB_USER", 'root');
define("DB_PASSWORD", '');
define("DB_NAME", 'be');
define("DB_HOST", 'localhost');
define("TABLES", '*');
$backupDatabase = new Backup_Database(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$backupDatabase->backupTables(TABLES);
class Backup_Database
{
    var $host = 'localhost';
    var $username = '******';
    var $passwd = '';
    var $dbName = 'be';
    var $charset = '';
    //set variables to connect to database
    function Backup_Database($host, $username, $passwd, $dbName, $charset = 'utf8')
    {
        $this->host = $host;
        $this->username = $username;
        $this->passwd = $passwd;
        $this->dbName = $dbName;
        $this->charset = $charset;
        $this->initializeDatabase();
    }
    //connect to database
    protected function initializeDatabase()
    {
        $conn = mysql_connect($this->host, $this->username, $this->passwd);
        mysql_select_db($this->dbName, $conn);