PHP code example of clearsoft / easysql-connectors
1. Go to this page and download the library: Download clearsoft/easysql-connectors 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/ */
clearsoft / easysql-connectors example snippets
use Clearsoft\EasySQL\Connectors\ConnectorEngine;
use Clearsoft\EasySQL\Connectors\ConnectorFactory;
use Clearsoft\EasySQL\Connectors\MySQL\ConnectionConfig;
$connector = ConnectorFactory::create(
ConnectorEngine::MySQL,
new ConnectionConfig(
host: '127.0.0.1', // default
port: 3306, // default
user: 'readonly',
password: 'secret', // in-memory only — never written to disk or logged
database: 'myapp',
),
);
$connector->connect();
try {
$raw = $connector->introspect(); // raw shape for the schema-generation package
$result = $connector->execute('SELECT * FROM users LIMIT 10', ['status' => 'active']);
// ['columns' => [...], 'rows' => [...], 'row_count' => N, 'duration_ms' => M]
} finally {
$connector->close();
}
use Clearsoft\EasySQL\Connectors\Postgres\Connector;
use Clearsoft\EasySQL\Connectors\Postgres\ConnectionConfig;
$connector = new Connector(new ConnectionConfig(host: 'db.internal', database: 'shop'));
use Clearsoft\EasySQL\Connectors\ConnectorEngine;
use Clearsoft\EasySQL\Connectors\ConnectorFactory;
// Redshift (PostgreSQL 8.0 based — relispartition is omitted), over TCP.
ConnectorFactory::create(ConnectorEngine::PostgreSQL, [
'provider' => 'redshift',
'host' => 'cluster.redshift.amazonaws.com',
'user' => 'admin',
'password' => 'secret',
'database' => 'analytics',
]);
// Neon over its HTTP SQL endpoint (one-shot queries, no persistent connection).
ConnectorFactory::create(ConnectorEngine::PostgreSQL, [
'provider' => 'neon',
'transport' => 'http',
'connectionString' => 'postgresql://user:[email protected]/db',
]);