PHP code example of sohris / reactphp-mysql

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

    

sohris / reactphp-mysql example snippets




$user = "user";
$password = "pass";
$host = "host";
$port = 3306;

//Create a new Connection
$connector = Sohris\Mysql\Connector\Factory::create($user, $password, $host, $port);

//Or
//Create a new lazy Connection
$connector = Sohris\Mysql\Connector\Factory::createLazyConnection($user, $password, $host, $port);

//Or
//To force a new connection, use a createLazyNewConnector
$connector = Sohris\Mysql\Connector\Factory::createLazyNewConnector($user, $password, $host, $port);


$connector->query("SELECT * FROM information_schema.ROUTINES Limit 1")
            ->then(function(Sohris\Mysql\Io\QueryResult $result){   
                        var_dump($result->resultRows);
                    },
                    function(Exception $e){
                        var_dump($e->getMessage());
                    });



$user = "user";
$password = "pass";
$host = "host";
$port = 3306;


//Create a connection
$connector = new \Sohris\Mysql\Pool($user, $password, $host, $port);

$connector->exec("SELECT * FROM information_schema.ROUTINES Limit 1")
            ->then(function(Sohris\Mysql\Io\QueryResult $result){   
                        echo "Result 1" . PHP_EOL;                        
                    },
                    function(Exception $e){
                        var_dump($e->getMessage());
                    });



$connector->setPoolSize(2);