PHP code example of easyswoole / mysqli-pool

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

    

easyswoole / mysqli-pool example snippets


use EasySwoole\Mysqli\Config;
use EasySwoole\MysqliPool;

$config1 = new Config();
$config2 = new Config;

Mysql::getInstance()->register('mysql1',$config1);
Mysql::getInstance()->register('mysql2',$config2);



use EasySwoole\MysqliPool\Mysql;
use EasySwoole\MysqliPool\Connection;
use EasySwoole\Mysqli\Config;

$config1 = new Config([
    'host'          => '',
    'port'          => 3306,
    'user'          => '',
    'password'      => '',
    'database'      => '',
    'timeout'       => 5,
    'charset'       => 'utf8mb4',
]);

$config2 = new Config([
    'host' => '',
    'port' => 3306,
    'user' => '',
    'password' => '',
    'database' => '',
    'timeout' => 5,
    'charset' => 'utf8mb4',
]);

//注册的时候会返回对应的poolConf
Mysql::getInstance()->register('my1',$config1);

Mysql::getInstance()->register('my2',$config2);

go(function (){
    $conn = Mysql::defer('my1');
    var_dump(count($conn->rawQuery('show tables')));

    $ret =  Mysql::invoker('my1',function (Connection $conn){
        return $conn->rawQuery('show tables');
    });
    var_dump(count($ret));
});

go(function (){
    $conn = Mysql::defer('my2');
    var_dump(count($conn->rawQuery('show tables')));

    $ret =  Mysql::invoker('my2',function (Connection $conn){
        return $conn->rawQuery('show tables');
    });
    var_dump(count($ret));
});