2017 © Pedro Peláez
 

library pirlo-db

Simple class to work with database

image

hilmanrdn/pirlo-db

Simple class to work with database

  • Monday, November 28, 2016
  • by hilmanrdn
  • Repository
  • 3 Watchers
  • 1 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 6 % Grown

The README.md

Pirlo_DB :: PDO Abstract Class

Abstract database class using PDO, the end syntax inspired by Eloquent from laravel but more basic implementations [Eloquent Laravel] (https://laravel.com/docs/5.1/eloquent). Not much tested yet, it made for my own learning purpose but feel free to use it on your project, and let me know if there are any bugs or anything i can improve., (*1)

Install

composer require "hilmanrdn/pirlo-db: dev-master"

Todo

  • show error, success or fail
  • return as JSON
  • join
  • other relations

Usage Example

  • Load database, (*2)

    use PirloDB\Database;
    
    require_once 'vendor/autoload.php';
    
    $test = Database::getInstance($server, $user, $pass, $db_name);
    $test->setTable($tableName);
    
  • Select and retrieve data, (*3)

    Always use select!, (*4)

    Select() can be blank to select all columns, or specify column(s) name in one string., (*5)

    There are two possibilities, use all() to get an array, or first() for only one data, (*6)

    $test->select()->all();
    $test->select()->first();
    $test->select('username, id')->first();
    
  • Where, (*7)

    Where() has 3 parameters (column, sign and value), (*8)

    It can be used multiple times to use 'AND', or use orwhere() to use 'OR', (*9)

    $test->where('username', '=', 'name')->first();
    $test->select('username')->where('username', '=', 'name')->all();
    $test->where('username', '=', 'hilman')->where('password', '=', 'password')->all();
    $test->where('username', '=', 'name1')->orWhere('username', '=', 'name2')->all();
    
  • Insert, (*10)

    Use create() and associatve array which formatted by column_name => column_value, (*11)

    $test->create([
    'username' => 'name',
    'password' => 'pass',
    ]);  
    
  • Update, (*12)

    Use where() to select which row want to be entered, (*13)

    $test->where('username', '=', 'name')->update([
    'username' => 'newName',
    'password' => 'newPass',
    ]);
    
  • Delete, (*14)

    Use where() to select which row want to be deleted, (*15)

    $test->where('username', '=', 'name')->delete();
    
  • orderBy, (*16)

    orderBy() has two parameter (column and type[DESC or ASC]), (*17)

    $test->select()->orderBy('username', 'DESC')->all();
    
  • take, (*18)

    take to limit the result, put the number as parameter, if chained with orderBy(), orderBy() must be used first, (*19)

    $test->select()->orderBy('username', 'DESC')->take(3)->all();
    

The Versions

28/11 2016

dev-master

9999999-dev

Simple class to work with database

  Sources   Download

The Requires

  • php >=5.3.0