Luminova Framework

PHP Luminova: Backup and Export Module for Databases

Last updated: 2026-11-28 20:57:12

Database manager class allows you to create a backup of your database and tables, and export them as a CSV or JSON format.

The Backup & Export Manager class allows you to create backups of your database, database table or export specific table columns as CSV or JSON files. MySQL backups are written under writeable/backups/. CSV and JSON are the formats accepted by the export API.


Class Definition


Methods

constructor

Initializes database manager class with an active database driver.

public function __construct(
    DatabaseDriverInterface $db,
    ?string $table = null
)

Parameters:

ParameterTypeDescription
$dbDatabaseDriverInterfaceThe database driver interface.
$table?stringThe name of the table to manage (default null).

Example:

use Luminova\Database\Connection;
use Luminova\Database\Manager;

$db = (new Connection())->database();
$manager = new Manager($db, 'users');

$manager->backup('users', forTable: true);

setTable

Sets the database table to backup or export.

public function setTable(string $table): self

Parameters:

ParameterTypeDescription
$tablestringThe database table name.

Return:

self - Return instance of manager class.


export

Accepts a table selection and download options for a CSV or JSON export.

public function export(string $as = 'csv', ?string $filename = null, array $columns = ['*']): bool

Parameters:

ParameterTypeDescription
$asstringFormat to export (e.g, csv or json) (default 'csv').
$filename?stringThe name of the file to download (default null).
$columnsstring[]The columns to export (default: [*]all columns).

Return:

bool - Return true on success else false.

Throws:


backup

Creates a backup of the current database or a specific table.

public function backup(?string $filename = null, bool $forTable = false): bool

Parameters:

ParameterTypeDescription
$filename?stringThe name of the backup file (default null).
$forTableboolWhether to back up a specific table or the entire database (default: false).

Return:

bool - Return true on success else false.

Throws: