DBLayer, PHP ORM
DB layers for mysqli extension and PDO class. DBLayer is working with mappers (files holding tables' properties) to provide safer SQL operations., (*1)
Installing DBLayer
The recommended way to install DBLayer is through
Composer., (*2)
# Install Composer
curl -sS https://getcomposer.org/installer | php
Next, run the Composer command to install the latest stable version of DBLayer:, (*3)
composer require tesis/db-layer
# Add scripts to composer json:
"scripts": {
"post-update-cmd": "DBLayer\\Loader::postUpdate",
"post-install-cmd": "DBLayer\\Loader::postInstall"
}
or insert in your composer:, (*4)
"require": {
"tesis/db-layer": "1.0.x-dev"
},
"require-dev": {
"phpunit/phpunit": "^6.5"
},
"scripts": {
"post-update-cmd": "DBLayer\\Loader::postUpdate",
"post-install-cmd": "DBLayer\\Loader::postInstall"
}
# Run: composer update / composer install
After installing, you need to require Composer's autoloader:, (*5)
require 'vendor/autoload.php';
You can then later update DBLayer using composer:, (*6)
bash
composer update
, (*7)
DB Layer - ORM
migrate sql files (simple SQL, see folders db/migrations, db/seeders), (*8)
generate database mapper (default - json format, optional (.ini file, or .php file returning an array)
(examples of generated files are in tests/data folder), (*9)
for CRUD or select statements, provided two layers: mysqli and PDO, (*10)
Start with, (*11)
# Change database credentials, write env.ini file
php vendor/tesis/db-layer/init
Credentials
add/change credentials in config/dbLayer.php file, (*12)
Migrate
if you database and / or tables are not yet created,
create them manually or prepare simple migration and seeder file
(examples in database/migrations and database/seeders dir), (*13)
php vendor/tesis/db-layer/migrator
after running migrator, new database is created
tables are created
tables are populated, (*14)
Example of configuration file
$config = [
'dbHost' => 'localhost',
'dbUser' => 'user',
'dbPass' => 'pass',
'dbName' => 'test_db',
'dbCharset' => 'utf8',
'mapperDir' => 'mappers',
'mapperFile' => 'dbTablesMapper',
'mapperType' => 'json',
'contactEmail' => 'your_email@dot.com',
'environment' => 'dev',
'debug' => true
];
Geneate table mapper
run the command bellow and you'll be guided through the process, (*15)
php vendor/tesis/db-layer/generator
Documentation / Usage
At the moment, there are examples provided in example dir., (*16)
License
MIT License, (*17)
Last Version
1.0, (*18)