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();
}

$connector = ConnectorFactory::create(ConnectorEngine::SQLite, [
    'path' => '/srv/myapp.db',
    'readOnly' => true,
]);

$connector = ConnectorFactory::create(ConnectorEngine::MySQL, 'mysql://app:[email protected]:3306/shop');
$connector = ConnectorFactory::create(ConnectorEngine::SQLite, 'sqlite:///srv/myapp.db');

$connector = ConnectorFactory::create(ConnectorEngine::MySQL, [
    'host' => 'ignored-when-a-socket-is-set',
    'socket' => '/var/run/mysqld/mysqld.sock',
    'user' => 'wp',
    'password' => 'secret',
    'database' => 'wordpress',
]);

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',
]);

ConnectorFactory::create(ConnectorEngine::PostgreSQL, [
    'socket' => '/var/run/postgresql',
    'user' => 'postgres',
    'password' => 'secret',
    'database' => 'analytics',
]);