PHPackages                             oluokunkabiru/database-exporter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. oluokunkabiru/database-exporter

ActiveLibrary[Database &amp; ORM](/categories/database)

oluokunkabiru/database-exporter
===============================

Simple and elegant PHP/Laravel database exporter package that exports databases to SQL files and downloads them locally without phpMyAdmin login.

v2.2.3(2mo ago)010MITPHPPHP &gt;=8.0

Since Apr 8Pushed 2mo agoCompare

[ Source](https://github.com/oluokunkabiru/database-exporter)[ Packagist](https://packagist.org/packages/oluokunkabiru/database-exporter)[ Docs](https://github.com/oluokunkabiru/database-exporter)[ RSS](/packages/oluokunkabiru-database-exporter/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependencies (2)Versions (13)Used By (0)

Database Exporter
=================

[](#database-exporter)

A powerful Laravel/PHP package that allows you to export and download database backups without needing access to phpMyAdmin or terminal commands.

Features
--------

[](#features)

- 🎯 Export entire database or specific tables
- 📥 Download SQL files directly to your machine or store in cloud
- 🚀 Simple web-based UI with Livewire components
- 💻 CLI commands for automated backups and scheduling
- 🔒 Support for Laravel and vanilla PHP connections
- ⚙️ Configurable export options (compression, formatting, DROP TABLE statements)
- 📊 Real-time export progress tracking
- 🎨 Clean and intuitive TailwindCSS dashboard interface
- 💾 Multiple export formats: SQL, CSV
- 🗜️ Built-in compression support (ZIP)
- 👁️ Include views, triggers, and stored procedures

Installation
------------

[](#installation)

### Step 1: Install via Composer

[](#step-1-install-via-composer)

```
composer require oluokunkabiru/database-exporter
```

### Step 2: Publish Configuration (Laravel only)

[](#step-2-publish-configuration-laravel-only)

```
php artisan vendor:publish --tag=database-exporter-config
```

### Step 3: Publish Views (optional)

[](#step-3-publish-views-optional)

```
php artisan vendor:publish --tag=database-exporter-views
```

Quick Start
-----------

[](#quick-start)

### Laravel - Web Interface

[](#laravel---web-interface)

1. Visit `/database-exporter` in your browser
2. Select tables to export
3. Configure export options
4. Click "Start Export"
5. Download the file

### Laravel - CLI Command

[](#laravel---cli-command)

```
# Export entire database as SQL
php artisan db:export

# Export specific tables
php artisan db:export --tables=users,posts,comments

# Export as CSV (creates ZIP)
php artisan db:export --format=csv

# Compress the export
php artisan db:export --compress

# Include views and triggers
php artisan db:export --include-views --include-triggers

# Without DROP TABLE statements
php artisan db:export --no-drop

# All options combined
php artisan db:export \
  --tables=users,posts \
  --format=sql \
  --compress \
  --include-views \
  --include-triggers

# Specify output filename
php artisan db:export --output=backup-2024.sql
```

### Laravel - Programmatic Usage

[](#laravel---programmatic-usage)

```
use Oluokunkabiru\DatabaseExporter\DatabaseExporter;
use Oluokunkabiru\DatabaseExporter\ConnectionResolver;

// Automatically detect connection
$exporter = new DatabaseExporter(ConnectionResolver::resolve());

// Export entire database
$filepath = $exporter
    ->compress(true)
    ->addDropTable(true)
    ->export();

echo "Backup saved to: " . $filepath;

// Export specific tables
$filepath = $exporter
    ->tables(['users', 'posts', 'comments'])
    ->format('csv')
    ->export();

// Get database information
$info = $exporter->getDatabaseInfo();
echo "Database: " . $info['name'];
echo "Tables: " . $info['table_count'];
echo "Size: " . $info['size_formatted'];
```

### Vanilla PHP - Manual Connection

[](#vanilla-php---manual-connection)

```
require 'vendor/autoload.php';

use Oluokunkabiru\DatabaseExporter\DatabaseExporter;
use PDO;

$connection = new PDO(
    'mysql:host=localhost;dbname=my_database;charset=utf8mb4',
    'root',
    'password',
    [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    ]
);

$exporter = new DatabaseExporter($connection);

$filepath = $exporter
    ->tables(['users', 'posts'])
    ->format('sql')
    ->compress(true)
    ->export();

echo "Export completed: " . basename($filepath);
```

### Vanilla PHP - Environment-based Connection

[](#vanilla-php---environment-based-connection)

```
require 'vendor/autoload.php';

use Oluokunkabiru\DatabaseExporter\ConnectionResolver;
use Oluokunkabiru\DatabaseExporter\DatabaseExporter;

// Set environment variables
$_ENV['DB_HOST'] = 'localhost';
$_ENV['DB_PORT'] = 3306;
$_ENV['DB_DATABASE'] = 'my_database';
$_ENV['DB_USERNAME'] = 'root';
$_ENV['DB_PASSWORD'] = '';

// Automatically resolve connection
$connection = ConnectionResolver::resolveFromEnv();
$exporter = new DatabaseExporter($connection);

$filepath = $exporter->export();
```

Configuration
-------------

[](#configuration)

Edit `config/database-exporter.php` to customize:

```
return [
    // Enable/disable the web dashboard
    'dashboard_enabled' => true,

    // Route prefix for dashboard
    'route_prefix' => 'database-exporter',

    // Default export format (sql or csv)
    'default_format' => 'sql',

    // Enable compression by default
    'enable_compression' => true,

    // Directory where exports are stored
    'backup_directory' => storage_path('exports'),

    // Include database views
    'include_views' => false,

    // Include database triggers
    'include_triggers' => false,

    // Include stored procedures
    'include_procedures' => false,

    // Add DROP TABLE statements
    'add_drop_table' => true,

    // SQL formatting (pretty or minified)
    'sql_format' => 'pretty',

    // Max execution time in seconds
    'max_execution_time' => 900,

    // Require authentication
    'require_auth' => true,

    // Allowed roles (empty = all authenticated users)
    'allowed_roles' => ['admin', 'super_admin'],
];
```

Usage Examples
--------------

[](#usage-examples)

### Scheduled Backups

[](#scheduled-backups)

```
// In app/Console/Kernel.php

protected function schedule(Schedule $schedule)
{
    $schedule->call(function () {
        $exporter = app('database-exporter');

        $filepath = $exporter
            ->compress(true)
            ->export();

        // Store in cloud
        Storage::disk('s3')->put(
            'backups/database-' . date('Y-m-d-His') . '.zip',
            file_get_contents($filepath)
        );

        // Clean old backups
        $this->deleteOldBackups();

    })->daily()->at('02:00');
}

protected function deleteOldBackups()
{
    $backupDir = storage_path('exports');
    $thirtyDaysAgo = time() - (30 * 24 * 60 * 60);

    foreach (glob($backupDir . '/*') as $file) {
        if (filemtime($file) < $thirtyDaysAgo) {
            unlink($file);
        }
    }
}
```

### API Endpoint

[](#api-endpoint)

```
// In routes/api.php

Route::middleware('auth:sanctum')->group(function () {
    Route::post('/export', function (Request $request) {
        $exporter = app('database-exporter');

        $filepath = $exporter
            ->tables($request->input('tables', []))
            ->format($request->input('format', 'sql'))
            ->compress($request->boolean('compress', true))
            ->export();

        return response()->download($filepath);
    });
});
```

Available Methods
-----------------

[](#available-methods)

### Configuration Methods

[](#configuration-methods)

MethodDescriptionType`setConnection(PDO $connection)`Set database connectionself`setDatabase(string $database)`Set database nameself`tables(array $tables)`Select specific tablesself`format(string $format)`Set export format (sql, csv)self`compress(bool $compress)`Enable/disable compressionself`includeViews(bool $include)`Include database viewsself`includeTriggers(bool $include)`Include triggersself`addDropTable(bool $add)`Add DROP TABLE statementsself`sqlFormat(string $format)`Set SQL formatting (pretty, minified)self### Query Methods

[](#query-methods)

MethodDescriptionReturn`getDatabaseInfo()`Get database informationarray`getAllTables()`Get all table namesarray`getTableInfo(string $table)`Get table informationarray`export(?string $filename, ?callable $progressCallback)`Export databasestring (filepath)Security
--------

[](#security)

- ✅ Authentication required by default (configurable)
- ✅ Role-based access control
- ✅ File path validation (prevents directory traversal)
- ✅ Database connection validation
- ✅ Temporary file cleanup

Performance
-----------

[](#performance)

- ⚡ Optimized for large databases
- ⚡ Batch inserts (100 rows per batch)
- ⚡ Progress callbacks for UI updates
- ⚡ Streaming downloads (no memory overload)
- ⚡ Optional compression for smaller files

Troubleshooting
---------------

[](#troubleshooting)

### "Database connection not set"

[](#database-connection-not-set)

Make sure you're passing a valid PDO connection or using `ConnectionResolver::resolve()`.

### Export takes too long

[](#export-takes-too-long)

- Increase `max_execution_time` in config
- Export specific tables instead of entire database
- Use compression to speed up downloads

### "File not found" on download

[](#file-not-found-on-download)

Make sure the backup directory exists and has write permissions:

```
mkdir -p storage/exports
chmod 755 storage/exports
```

### Connection refused

[](#connection-refused)

Verify your database credentials in `.env`:

```
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=your_database
DB_USERNAME=root
DB_PASSWORD=password

```

Requirements
------------

[](#requirements)

- PHP &gt;= 8.0
- Laravel &gt;= 9.0 (for Laravel integration)
- MySQL &gt;= 5.7 or MariaDB &gt;= 10.2
- Livewire &gt;= 3.0 (for web dashboard)

License
-------

[](#license)

MIT

Support
-------

[](#support)

For issues, questions, or contributions, please visit the GitHub repository.

Credits
-------

[](#credits)

Created by Oluokun Kabiru Adesina

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance88

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

12

Last Release

62d ago

Major Versions

v1.4.5 → v2.0.02026-04-08

### Community

Maintainers

![](https://www.gravatar.com/avatar/94fd074663fdc66b70cd016c3ace6abf367180c148532aa142cc4359543ae753?d=identicon)[devvboy](/maintainers/devvboy)

---

Top Contributors

[![oluokunkabiru](https://avatars.githubusercontent.com/u/47401341?v=4)](https://github.com/oluokunkabiru "oluokunkabiru (14 commits)")

---

Tags

phplaraveldatabasebackupexportsqldownloaddatabase backup

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/oluokunkabiru-database-exporter/health.svg)

```
[![Health](https://phpackages.com/badges/oluokunkabiru-database-exporter/health.svg)](https://phpackages.com/packages/oluokunkabiru-database-exporter)
```

###  Alternatives

[illuminate/database

The Illuminate Database package.

3.0k54.1M11.0k](/packages/illuminate-database)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592452.8k2](/packages/spiritix-lada-cache)[nwidart/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

37839.1k](/packages/nwidart-db-exporter)[itpathsolutions/dbstan

Database Standardization and Analysis Tool for Laravel

442.1k](/packages/itpathsolutions-dbstan)[calebdw/laravel-sql-entities

Manage SQL entities in Laravel with ease.

311.5k](/packages/calebdw-laravel-sql-entities)[elimuswift/db-exporter

Export your database quickly and easily as a Laravel Migration and all the data as a Seeder class.

364.7k](/packages/elimuswift-db-exporter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
