PHP code example of userqq / mysql-binlog

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

    

userqq / mysql-binlog example snippets


use UserQQ\MySQL\Binlog\Config;

$config = (new Config())
    ->withUser('root')
    ->withPassword('toor');

withUser(string $user): static                   // Database user with replication privileges

withPassword(string $password): static           // Database user's password

withHost(string $host): static                   // Database host

withPort(int $port): static                      // Database host

withBinlogFile(?string $binlogFile): static      // Binlog file to start from

withBinlogPosition(?int $binlogPosition): static // Position in binlog file to start from

 declare(strict_types=1);

;
use UserQQ\MySQL\Binlog\EventsIterator;

$config = (new Config())
    ->withUser('root')
    ->withPassword('toor');

$eventsIterator = new EventsIterator($config);

foreach ($eventsIterator as $position => $event) {
    echo json_encode($position) . PHP_EOL;
    echo json_encode($event, JSON_PRETTY_PRINT) . PHP_EOL;
    echo PHP_EOL;
}