Delete Database
SwartzDB provides a delete function that allows you to remove database files permanently. This function can be used to delete both main database files and backup files.
Using the delete Function
To delete a database, use the following method:
$sdb->delete("main", "mydatabase");
Parameters:
"main"– Specifies that you are deleting a main database file."mydatabase"– The name of the database file to be deleted (without the.sdbextension).
This will locate and delete the file mydatabase.sdb from the default storage location.
Deleting a Backup Database
If you want to delete a backup database file, specify "backup" as the first parameter:
$sdb->delete("backup", "mydatabase_backup.bak");
How It Works:
- By default, backups are stored in a folder called
"backup"inside the storage directory. - This function will look for
mydatabase_backup.bakinside the backup folder and delete it.
Customizing the Backup Folder Path
If your backup files are stored in a different folder, you can specify the backup folder name as a third parameter:
$sdb->delete("backup", "old_backup.bak", "my_backups");
This will delete old_backup.bak from the /my_backups/ directory.
Return Value
The function returns:
trueif the file was successfully deleted.falseif the file does not exist or deletion failed.
Important Notes
- Permanent Deletion: Deleting a main database file will remove it permanently. Ensure you have a backup if needed.
- File Name Must Be Exact: The function does not assume file extensions for backups, so always provide the full file name for backups.
- Check Before Deleting: It is recommended to verify the existence of a file before attempting deletion to prevent errors.
By using the delete function, you can effectively manage and clean up unnecessary database files in SwartzDB.