PHP code example of thruster / mysql-client

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

    

thruster / mysql-client example snippets


use Thruster\Component\MysqlClient\Client;
use Thruster\Component\MysqlClient\ConnectionPool;
use Thruster\Component\EventLoop\EventLoop;

$loop = new EventLoop();

$connectionPool = new ConnectionPool(function () {
    return new mysqli('127.0.0.1', 'root', '', 'timeverz');
});

$client = new Client($loop, $connectionPool);

for ($i = 0; $i < 100; $i++) {
    $client->query('SELECT * FROM users;')->then(
        function (\mysqli_result $result) use ($i) {
            foreach ($result->fetch_all(MYSQLI_ASSOC) as $item) {
                echo $i . ': ' . $item['id'] . PHP_EOL;
            }
        },
        function ($error) {
            // TODO: Handle error
        }
    );
}

$loop->run();