Lightweight binary database by pure PHP
Go to file
Arsen Mirzaev Tatyano-Muradovich 1cd4fe8a9a fixed type::char and reading empty records 2025-01-31 11:54:33 +07:00
mirzaev/baza fixed type::char and reading empty records 2025-01-31 11:54:33 +07:00
.editorconfig fixed type::char and reading empty records 2025-01-31 11:54:33 +07:00
.gitignore fixed type::char and reading empty records 2025-01-31 11:54:33 +07:00
LICENSE move from mirzaev/repression 2024-11-23 09:50:05 +07:00
README.md spaces to tabs 2025-01-28 15:00:17 +07:00
composer.json renamed from ebaboba to baza; resolved #13 2025-01-28 14:14:13 +07:00
composer.lock renamed from ebaboba to baza; resolved #13 2025-01-28 14:14:13 +07:00

Baza

Lightweight binary database by pure PHP

Dependencies

  1. PHP 8.4
  2. Composer (php package manager)

Installation

composer require mirzaev/baza

Example

<?php

use mirzaev\baza\database,
    mirzaev\baza\column,
    mirzaev\baza\record,
    mirzaev\baza\enumerations\encoding,
    mirzaev\baza\enumerations\type;

// Initializing the database
$database = new database()
    ->encoding(encoding::utf8)
    ->columns(
        new column('name', type::string, ['length' => 32]),
        new column('second_name', type::string, ['length' => 64]),
        new column('age', type::integer),
        new column('height', type::float)
    )
    ->connect(__DIR__ . DIRECTORY_SEPARATOR . 'database.ba');

// Initializing the record
$record = $database->record(
    'Arsen',
    'Mirzaev',
    23,
    (float) 165
);

if ($database->write($record)) {
    // Writed the record into the database

    // Updating the record in the database
    $updated = $database->read(
        filter: fn($record) => $record->name === 'Arsen', 
        update: fn(&$record) => $record->age = 24, 
        amount: 1
    );

    // Reading the record from the database
    $readed = $database->read(
        filter: fn($record) => $record->name === 'Arsen' && $record->age === 24,
        amount: 1
    );

    // Deleting the record from the database
    $deleted = $database->read(
        filter: fn($record) => $record->age < 25,
        delete: true,
        amount: 1000
    );
}
?>

Used by