Luminova Framework

PHP Luminova: Database Backup and Export manager

Last updated: 2024-08-31 15:35:04

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

The Manager class allows you to create backups of your database, database table or export specific table columns as CSV or JSON files. All backups and exports are stored in /writeable/backups/ directory.


  • Class namespace: \Luminova\Database\Manager

Methods

constructor

Initializes database manager class with DriversInterface you are using.

public __construct(\Luminova\Interface\DriversInterface $db, ?string $table = null): mixed

Parameters:

ParameterTypeDescription
$db\Luminova\Interface\DriversInterfaceThe database driver interface.
$tablestring|nullThe name of the table to manage.

Get database manager instance from QueryBulder class.

$manager = $bilder->manager(): Manager;

setTable

Sets the database table to backup or export.

public setTable(string $table): void

Parameters:

ParameterTypeDescription
$tablestringThe database table name.

export

Exports the specified table and downloads it as a CSV or JSON file.

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

Parameters:

ParameterTypeDescription
$asstringFormat to export (e.g, csv or json).
$filenamestring|nullThe name of the file to download.
$columnsarrayThe columns to export (default: [*]all columns).

Return Value:

bool - Return true on success else false.

Throws:


backup

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

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

Parameters:

ParameterTypeDescription
$filenamestring|nullThe name of the backup file.
$forTableboolWhether to back up a specific table or the entire database (default: false).

Return Value:

bool - Return true on success else false.

Throws: