PHP code example of guirong / php-database
1. Go to this page and download the library: Download guirong/php-database library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
guirong / php-database example snippets
use Guirong\Database\Backup\MysqlBackup;
$config = [
'host' => '127.0.0.1',
'database' => 'my_database',
'username' => 'my_username',
'password' => 'my_password',
'port' => 3306,
];
$server = new MysqlBackup($config['host'],$config['username'],$config['database'],$config['password'],$config['port']);
$backupDir = '/www/wwwroot/my_project/database/backup/';
$result = $server->backup($backupDir);
if(!$result){
echo '备份失败,错误信息:'.$server->getError();
exit;
}
// 备份成功,获取备份文件路径
$backupFile = $server->getResponse();
$tables = ['table_shop','table_user','table_goods'];
$result = $server->setIgnoreTable($tables)->backup($backupDir);
$backupFileName = '我的mysql备份文件-1';
$result = $server->setBackupFilename($backupFileName)->setIgnoreTable($tables)->backup($backupDir);
use Guirong\Database\Backup\MysqlBackup;
$config = [
'host' => '127.0.0.1',
'database' => 'my_database',
'username' => 'my_username',
'password' => 'my_password',
'port' => 3306,
];
$server = new MysqlBackup($config['host'],$config['username'],$config['database'],$config['password'],$config['port']);
$backupFile = '/www/wwwroot/my_project/database/backup/mysql-my_database-202307131630.sql';
$result = $server->setRecoveryFile($backupFile)->recovery();
if(!$result){
echo '恢复失败,错误信息:'.$server->getError();
exit;
}
$tables = ['table_shop','table_user','table_goods'];
$server->setRecoveryFile($backupFile)->setRecoveryTable($tables)->recovery();
bash
composer