yousha/dbalite

A lightweight Dbal(Database Abstraction Layer) library for PHP.

1.0.7.3 2025-05-01 11:05 UTC

This package is auto-updated.

Last update: 2025-05-01 15:04:15 UTC


README

A lightweight DBAL(Database Abstraction Layer) library for PHP.

current version Build and Test Dependabot Updates CodeQL PHP issues repo size GitHub license contributions welcome

Contents

Overview

DBALite is a powerful yet lightweight Database Abstraction Layer(DBAL) library designed for PHP developers who need a simple, efficient, and secure way to interact with multiple database systems. Built with modern PHP practices in mind, DBALite provides a clean, intuitive API for performing database operations while ensuring security, flexibility, and performance.

Features

  • Database Drivers: Supports MySQL/MariaDB, OracleDB, and SQLite databases.
  • Schema Management: Create tables, add columns, drop tables, manage indexes, and more.
  • Schema Inspection: Retrieve tables, columns, and check column existence.
  • Query Builder: Build SQL queries dynamically using a fluent interface.
  • Migrations: Manage database schema changes with migration classes.
  • Entity Management: Map database rows to entities and perform CRUD operations.
  • Security: Sanitize inputs, validate data, and prevent XSS and SQL injection.
  • Transaction Handling: Begin, commit, or rollback transactions safely.
  • Query Logging: Log executed queries for debugging purposes.
  • Bulk Operations: Perform bulk inserts efficiently.
  • SSL Support: Secure connections with SSL certificates.
  • Dynamic Configuration: Merge and extend configuration settings at runtime.
  • Supported PHP: 8.3
  • Supported databases: MySQL/MariaDB(Default), OracleDB, SQLite
  • Supported platforms: Microsoft Windows, GNU+Linux, Apple MacOS

Requirements

  1. PHP >= 8.3
  2. Composer >= 2
  3. Database server(MySQL/MariaDB, OracleDB, or SQLite)

Installation

Via Composer:

composer require yousha/dbalite

Configuration

Create a configuration array with your database settings:

$config = [
    'host' => '127.0.0.1',
    'dbname' => 'test_database',
    'user' => 'test_username',
    'password' => 'test_password',
    'ssl_ca' => '/path/to/ca-cert.pem', // Optional: Path to SSL CA certificate
    'ssl_verify' => false,             // Optional: Disable server cert verification
];

Or configuration for OracleDB:

$config = [
    'driver' => OracleDriver::class,
    'database' => [
        'host' => '127.0.0.1',
        'port' => 1521,
        'dbname' => 'test_database',
        'user' => 'test_username',
        'password' => 'test_password',
    ],
];

Or configuration for SQLite:

$config = [
    'driver' => SQLiteDriver::class,
    'database' => [
        'path' => __DIR__ . '/testdatabase.sqlite',
    ],
];

Initialize Dbal instance:

use Yousha\DBALite\Dbal;
use Yousha\DBALite\ConfigManager;

$config = new ConfigManager([
    'database' => $config,
    'migrations_dir' => __DIR__ . '/migrations', // Optional: Path to migration files.
]);

$dbal = new Dbal($config);

Usage

Quick start snippet:

<?php

require 'vendor/autoload.php';

use Yousha\DBALite\ConfigManager;
use Yousha\DBALite\Dbal;

$config = new ConfigManager([
    'driver' => \Yousha\DBALite\Driver\MySQLDriver::class,
    'database' => [
        'host' => '127.0.0.1',
        'dbname' => 'test',
        'user' => 'root',
        'password' => '',
    ],
]);

$dbal = new Dbal($config);

$result = $dbal->getDriver()->query("SELECT 'Hello, DBALite!' AS message");
print_r($result);

QA/QC

Run tests to ensure everything works as expected:

composer test

Or:

vendor/bin/phpunit tests/

FAQ

See FAQ.txt file.

Support

For any question, issues and feature requests, open an issue..

Changelog

See CHANGELOG.txt file.

ToDo

See TODO.txt file.

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork repository.
  2. Create a new branch for your feature or bugfix.
  3. Submit a pull request with a detailed description of your changes.

For more details see CONTRIBUTING.txt.

Code of Conduct

See CODE_OF_CONDUCT.txt file.

DCO

See DCO.txt file.

Contributors

See CONTRIBUTORS.txt file.

Notice

See NOTICE.txt file.

License

This open-source software is distributed under the GPL-3.0 license. See LICENSE file.