A lightweight DBAL(Database Abstraction Layer) library for PHP.
- Overview
- Features
- Requirements
- Installation
- Configuration
- Usage
- FAQ
- Support
- Changelog
- ToDo
- Contributing
- Code of Conduct
- DCO
- Contributors
- Notice
- License
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.
- 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
- PHP >= 8.3
- Composer >= 2
- Database server(MySQL/MariaDB, OracleDB, or SQLite)
Via Composer:
composer require yousha/dbalite
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);
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);
Run tests to ensure everything works as expected:
composer test
Or:
vendor/bin/phpunit tests/
See FAQ.txt file.
For any question, issues and feature requests, open an issue..
See CHANGELOG.txt file.
See TODO.txt file.
Contributions are welcome! Please follow these steps:
- Fork repository.
- Create a new branch for your feature or bugfix.
- Submit a pull request with a detailed description of your changes.
For more details see CONTRIBUTING.txt.
See CODE_OF_CONDUCT.txt file.
See DCO.txt file.
See CONTRIBUTORS.txt file.
See NOTICE.txt file.
This open-source software is distributed under the GPL-3.0 license. See LICENSE file.