Last Updated: February 25, 2016
·
767
· kopiro

PDO Wrapper in PHP

Simple wrapper in PHP for Database connections using PDO.

KOPDO help you to DON'T rewrite everytime statements/fetch codes.

https://github.com/kopiro/KOPDO

Connect

KOPDO::connect(DB_STRING, DB_USER, DB_PASS);

Insert a new row

$id = KOPDO::insert('test', [
    'name'=> 'Flavio',
    'surname'=> 'Kopiro',
    'friends'=> ['A','B','C']
    'phones'=> [
        'ita'=> '+391231231234',
        'usa'=> '+02998898',
        'uk'=> ['09956','923752']
    ]
]);

The data passed as array/objects are automatically serialized in the database.

Select rows

KOPDO::all('test', 'name, surname, friends, phone');

Data are automatically unserialized when requested.

Will return an indexed array with inside an associative array with datas.

Update an existing row

KOPDO::update('test', ['name'=> 'Flavioooo'], 'id=:id', [ ':id'=>$id ]);

Select a single row

KOPDO::first('test', '*', 'id=:id', [':id'=>$id]);
KOPDO::first('test', '*', "name LIKE '%:name%'", [':name'=>'flavio']);

or

KOPDO::first('test', '*', 'id=1');

Will return an associative array with datas.

Select a list of things

KOPDO::indexed('test', 'id');

Will return an indexed array of IDs. [1,2,3,4]

Delete rows

KOPDO::delete('test', "name LIKE '%:name%'", [':name'=>'flavio']);