PHP code example of ereborcodeforge / mazarbul

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

    

ereborcodeforge / mazarbul example snippets


use EreborCodeForge\Mazarbul\Connection\ConnectionConfig;
use EreborCodeForge\Mazarbul\Connection\ConnectionManager;
use EreborCodeForge\Mazarbul\Connection\PdoConnectionFactory;

$manager = new ConnectionManager(new PdoConnectionFactory());

$manager->define('default', new ConnectionConfig(
    dsn: $_ENV['DB_DSN'],
    username: $_ENV['DB_USER'],
    password: $_ENV['DB_PASSWORD'],
));

$db = $manager->database('default'); // still no I/O

$user = $db->fetchOne('SELECT * FROM users WHERE id = ?', [$id]);

foreach ($db->stream('SELECT * FROM logs') as $row) {
    // one row at a time
}

$db->stream('SELECT id, email FROM users')
    ->pipeline()
    ->filter(static fn(array $row): bool => $row['email'] !== null)
    ->map(static fn(array $row): array => [
        ...$row,
        'email' => strtolower((string) $row['email']),
    ])
    ->chunk(500)
    ->each($processChunk);