Another PDO wrapper

1.0.6 2020-04-30 15:12 UTC

This package is auto-updated.

Last update: 2024-03-29 03:44:45 UTC


README

Tabusoft/DB is another DB wrapper to PDO/MySQL.

  • It's simple like PDO
  • Simplify the use of array values
  • Configurable with factory class and configuration

Installation

You can install it with composer

$ composer require tabusoft/db

Use

Direct instance of DB.

You can directly pass an array to query to bind ? parameters.

<?php
$db = new \Tabusoft\DB\DB("localhost", 'db-name', 'username', 'password');
$qres = $db->query("SELECT *
                        FROM table 
                        WHERE c1 = ? 
                            OR c2 IN (?) 
                            OR c3 = ?", 
                    [
                        1, //c1
                        [3,4,5], //c2 parameter extends the placeholder as array
                        1 //c3
                    ] );

echo PHP_EOL."Found: ".$qres->rowCount().PHP_EOL;

foreach($qres as $r){
    dump($r);
}

Use with the factory class

<?php 
$config = new \Tabusoft\DB\DBFactoryConfig("localhost", 'db-name', 'username', 'password');

$db = \Tabusoft\DB\DBFactory::getInstance($config);

Query events

You can add query events. Pre and Post execution:

class Event implements \Tabusoft\DB\DBEventsQueryInterface
{
    public function __invoke(DB $db, $sql, array $infos)
    {
        dump($infos);
    }
}

$db = \Tabusoft\DB\DBFactory::getInstance($config);
$db->addEvent(new Event(), DB::EVENT_PRE_QUERY);
$db->addEvent(new Event(), DB::EVENT_POST_QUERY);