PHP code example of tabusoft / db

1. Go to this page and download the library: Download tabusoft/db library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tabusoft / db example snippets



$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);
}
 
 
$config = new \Tabusoft\DB\DBFactoryConfig("localhost", 'db-name', 'username', 'password');

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


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);