Ci4 Database Backup is a PHP library designed to facilitate database backups for applications built with CodeIgniter 4 and other PHP Frameworks. It's able to operate in native PHP project too. This library provides an easy way to create SQL dumps of your MySQL databases.
Ci4 Database Backup is a PHP library designed to facilitate database backups for applications built with CodeIgniter 4 and other PHP Frameworks. It's able to operate in native PHP project too. This library provides an easy way to create SQL dumps of your MySQL databases.
You can install this library via Composer. Run the following command:
composer require aaronmk44/ci4-db-backup
Here is an example of how to use the Ci4 Database Backup
library:
Include Autoload File: Ensure you include the Composer autoload file in your script.
Create a Backup Script:
<?php
require './vendor/autoload.php'; // Autoload classes
use Ci4DbBackup\Ci4DbBackup;
(new Ci4DbBackup([
'host' => 'localhost',
'username' => 'root',
'password' => ''
]))->backup('test_db', 'path/to/backups');
In this example:
Ci4DbBackup
class is instantiated with database connection details (host, username, and password).backup
method is called with the database name (test_db
) and the path where the backup file should be saved.For more advanced usage and options, refer to the documentation.
__construct
Initializes the Ci4DbBackup
class with database connection details.
public function __construct(array $dbConfig)
host
: Database host (e.g., localhost
)username
: Database usernamepassword
: Database passwordbackup
Creates a backup of the specified database.
public function backup(string $database, string $backupPath)
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please fork the repository and submit a pull request with your improvements.
https://dev.to/joemoses33/create-a-composer-package-how-to-29kn