2017 © Pedro Peláez
 

library db-layer

Simple DB layer for mysqli extension and PDO class. It is based on mappers, files holding database table fields, primary key and auto_increment properties, which is helpful to compare fields for CRUD or select operations, and to provide better way to prevent SQL injections (only existing fields are selected, or inserted, ...)

image

tesis/db-layer

Simple DB layer for mysqli extension and PDO class. It is based on mappers, files holding database table fields, primary key and auto_increment properties, which is helpful to compare fields for CRUD or select operations, and to provide better way to prevent SQL injections (only existing fields are selected, or inserted, ...)

  • Wednesday, May 9, 2018
  • by tesis
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

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)

The Versions

09/05 2018

dev-master

9999999-dev https://github.com/tesis/db-layer

Simple DB layer for mysqli extension and PDO class. It is based on mappers, files holding database table fields, primary key and auto_increment properties, which is helpful to compare fields for CRUD or select operations, and to provide better way to prevent SQL injections (only existing fields are selected, or inserted, ...)

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

by Tereza Simcic

crud wrapper mapper pdo mysqli sql injection sql-generator