yousha/dbalite
最新稳定版本:2.0.0
Composer 安装命令:
composer require yousha/dbalite
包简介
A lightweight DBAL(Database Abstraction Layer) library for PHP.
关键字:
README 文档
README
A lightweight DBAL(Database Abstraction Layer) library for PHP.
Contents
- Overview
- Features
- Requirements
- Installation
- Configuration
- Usage
- Support
- Changelog
- Contributing
- Code of Conduct
- DCO
- Contributors
- Notice
- License
Overview
DBALite is a powerful yet lightweight Database Abstraction Layer(DBAL) library by DataMapper pattern. It is 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
- Supports MySQL/MariaDB, OracleDB, and SQLite databases.
- Create tables, add columns, drop tables, manage indexes, and more.
- Retrieve tables, columns, and check column existence.
- Build SQL queries dynamically using a fluent interface.
- Manage database schema changes with migration classes.
- Map database rows to entities and perform CRUD operations.
- Sanitize inputs, validate data, and prevent XSS and SQL injection.
- Begin, commit, or rollback transactions safely.
- Log executed queries for debugging purposes.
- Perform bulk inserts efficiently.
- Secure connections with SSL certificates.
- Merge and extend configuration settings at runtime.
- Supports PHP >= 8.*.
- Supports MySQL/MariaDB(Default), OracleDB, SQLite databases.
- Supports Microsoft Windows, GNU+Linux, Apple MacOS.
Requirements
- PHP >= 8.*
- Composer >= 2
- 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/
Support
For any question, issues and feature requests, open an issue..
Changelog
See CHANGELOG.txt file.
Contributing
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.
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.
统计信息
- 总下载量: 14
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-only
- 更新时间: 2025-05-21