1. Go to this page and download the library: Download gemvc/connection-openswoole 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/ */
gemvc / connection-openswoole example snippets
use Gemvc\Database\Connection\OpenSwoole\SwooleConnection;
// Set environment variables (or use defaults)
$_ENV['DB_DRIVER'] = 'mysql';
$_ENV['DB_HOST'] = 'db';
$_ENV['DB_NAME'] = 'my_database';
$_ENV['DB_USER'] = 'my_user';
$_ENV['DB_PASSWORD'] = 'my_password';
$_ENV['MIN_DB_CONNECTION_POOL'] = '8';
$_ENV['MAX_DB_CONNECTION_POOL'] = '16';
// Get singleton instance (creates connection pool)
$manager = SwooleConnection::getInstance();
// Get connection from pool (real implementation - connection pooling)
$connection = $manager->getConnection();
// Get underlying PDO instance
$pdo = $connection->getConnection();
// Use PDO directly
$stmt = $pdo->prepare("SELECT * FROM users");
$stmt->execute();
// Or use connection interface methods
$connection->beginTransaction();
$connection->commit();
// Release connection back to pool
$manager->releaseConnection($connection);
use Gemvc\Database\Connection\OpenSwoole\SwooleConnection;
// Set environment for PostgreSQL
$_ENV['DB_DRIVER'] = 'pgsql';
$_ENV['DB_HOST'] = 'postgres';
$_ENV['DB_NAME'] = 'my_database';
$_ENV['DB_USER'] = 'my_user';
$_ENV['DB_PASSWORD'] = 'my_password';
// Get connection
$manager = SwooleConnection::getInstance();
$connection = $manager->getConnection();
$pdo = $connection->getConnection();
// Use PostgreSQL connection
$pdo->exec('SELECT * FROM users');
use Gemvc\Database\Connection\OpenSwoole\SwooleConnectionAdapter;
use Hyperf\DbConnection\Connection;
// Get Hyperf Connection from pool (or create manually)
$hyperfConnection = $pool->get();
// Wrap in adapter for contracts
$adapter = new SwooleConnectionAdapter($hyperfConnection);
// Now implements ConnectionInterface
$adapter->beginTransaction();
$adapter->commit();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.