friends-of-reactphp / mysql

Async MySQL database client for ReactPHP.
MIT License
331 stars 66 forks source link

simple mysql pool #176

Closed wpjscc closed 9 months ago

wpjscc commented 1 year ago

Hi ,this pr add a simple mysql pool

query

use React\MySQL\Pool;
use React\MySQL\QueryResult;

$pool = new Pool('test:test@localhost/test');

$pool->query($sql, $params)->then(function (QueryResult $command) {

            if (isset($command->resultRows)) {
                // this is a response to a SELECT etc. with some rows (0+)
                print_r($command->resultFields);
                print_r($command->resultRows);
                echo count($command->resultRows) . ' row(s) in set' . PHP_EOL;
            } else {
                // this is an OK message in response to an UPDATE etc.
                if ($command->insertId !== 0) {
                    var_dump('last insert ID', $command->insertId);
                }
                echo 'Query OK, ' . $command->affectedRows . ' row(s) affected' . PHP_EOL;
            }
        }, function (\Exception $error) {
            // the query was not executed successfully
            echo 'Error: ' . $error->getMessage() . PHP_EOL;
        });

query stream

use React\MySQL\Pool;

$pool = new Pool('test:test@localhost/test');
$stream = $pool->queryStream($sql, $params);
 $stream->on('data', function ($row) {
        print_r($row);
  });
    $stream->on('error', function ($err) {
        echo 'Error: ' . $err->getMessage() . PHP_EOL;
    });
    $stream->on('end', function () {
        echo 'Completed:'. PHP_EOL;
    });
SimonFrings commented 9 months ago

Hey @wpjscc, thanks for opening this PR :+1:

To give you an update, we're currently starting to work on a solution for the MySQL connection pool feature as I described in https://github.com/friends-of-reactphp/mysql/issues/175#issuecomment-1785311945.

There seems to be a lot of overlap between your suggested changes and our vision for a connection pool, definitely some good input in here. In addition to implementing the feature itself, we also need multiple tests to assure the pool feature works as expected and some documentation to describe its usage, which is currently missing from this PR.

As I said, we're also working on this feature, so I think it makes sense that we invest time to add the necessary tests and documentation and create a separate pull request to add the connection pool. This is why I think we can close this pull request here and wait for our upcoming PR to get this feature in.

Thanks again for your work on this :rocket: