PHP code example of brick / db

1. Go to this page and download the library: Download brick/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/ */

    

brick / db example snippets


use Brick\Db\Bulk\BulkInserter;

$pdo = new PDO(...);
$inserter = new BulkInserter($pdo, 'user', ['id', 'name', 'age'], 100);

$inserter->queue(1, 'Bob', 20);
$inserter->queue(2, 'John', 22);
$inserter->queue(3, 'Alice', 24);

$inserter->flush();

use Brick\Db\Bulk\BulkDeleter;

$pdo = new PDO(...);
$deleter = new BulkDeleter($pdo, 'user', ['id']);

$deleter->queue(1);
$deleter->queue(2);
$deleter->queue(3);

$deleter->flush();

use Brick\Db\Bulk\BulkDeleter;

$pdo = new PDO(...);
$deleter = new BulkDeleter($pdo, 'user_product', ['user_id', 'product_id]);

$deleter->queue(1, 123);
$deleter->queue(2, 456);
$deleter->queue(3, 789);

$deleter->flush();

$pdo = new PDO(...);
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);

$inserter = new BulkInserter($pdo, 'user', ['id', 'name', 'age']);
$pdo->beginTransaction();

$inserter->queue(...);
// more queue() calls...

$inserter->flush();
$pdo->commit();