PHP code example of plasma / core

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

    

plasma / core example snippets


use Plasma\Client;
use Plasma\QueryResultInterface;
use React\EventLoop\Factory;
use SomeGuy\PlasmaDriver\MsSQLFactory;

$loop = Factory::create();
$factory = new MsSQLFactory($loop);

$client = Client::create($factory, 'root:1234@localhost');

$client->execute('SELECT * FROM `users`', [])
    ->then(function (QueryResultInterface $result) use ($client) {
        // Do something with the query result
        // Most likely for a SELECT query,
        // it will be a streaming query result
        
        $client->close()->done();
    }, function (Throwable $error) use ($client) {
        // Oh no, an error occurred!
        echo $error.PHP_EOL;
        
        $client->close()->done();
    });

$loop->run();

// Inside a coroutine
use Plasma\CursorInterface;

/** @var CursorInterface  $cursor */
$cursor = yield $client->createReadCursor('SELECT * FROM `my_table`');

while($row = yield $cursor->fetch()) {
    // Process row
}