C
C
Carlyndow Marlifi2021-06-21 17:52:40
PHP
Carlyndow Marlifi, 2021-06-21 17:52:40

How to make a database backup with PHP?

#code.. (PHP)

<?php 
$backup_folder = '/www/site.ru/backup';    // куда сохранятся файлы - полный путь ИЛИ  /backup
$backup_name = 'datebase_backup_' . date("Y-m-d");    // имя нового файла

$db_host = 'localhost';
$db_user = 'petuh';
$db_password = '12345';
$db_name = 'petuh';

function backupDB($backup_folder, $backup_name){
  global $db_host;
  global $db_user;
  global $db_password;
  global $db_name;
    $fullFileName = $backup_folder . '/' . $backup_name . '.sql';
    $command = 'mysqldump -h' . $db_host . ' -u' . $db_user . ' -p' . $db_password . ' ' . $db_name . ' > ' . $fullFileName;
    shell_exec($command);
    return $fullFileName;

}
backupDB($backup_folder, $backup_name);


The script does not do its job.
Things are done on Reg.ru

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question