PHP code example of darkspock / just-query

1. Go to this page and download the library: Download darkspock/just-query 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/ */

    

darkspock / just-query example snippets


use JustQuery\Driver\Mysql\Connection;

$db = Connection::fromDsn(
    dsn: 'mysql:host=127.0.0.1;dbname=myapp;port=3306',
    username: 'root',
    password: 'secret',
);

$db->open();

use JustQuery\Driver\Pgsql\Connection;

$db = Connection::fromDsn(
    dsn: 'pgsql:host=127.0.0.1;dbname=myapp;port=5432',
    username: 'postgres',
    password: 'secret',
);

$db->open();

use JustQuery\Driver\Mysql\Connection;

// Reuse a PDO instance from your framework (CodeIgniter, Laravel, etc.)
// Use the matching Connection class for your driver.
$db = Connection::fromPdo($existingPdo);

use JustQuery\Cache\SchemaCache;
use JustQuery\Driver\Mysql\{Connection, Driver};

$driver = new Driver(
    'mysql:host=127.0.0.1;dbname=myapp;port=3306',
    'root',
    'secret',
);

$schemaCache = new SchemaCache($psr16Cache);
$db = new Connection($driver, $schemaCache);

$db->open();                    // Establish connection
$db->isActive();                // true if connected
$db->close();                   // Close connection
$db->getDriverName();           // 'mysql' or 'pgsql'
$db->getLastInsertId();         // Last auto-increment ID
$db->getSchema();               // SchemaInterface
$db->getTableSchema('users');   // TableSchemaInterface for a specific table
$db->getQueryBuilder();         // QueryBuilderInterface
$db->getQuoter();               // QuoterInterface

$db->setTablePrefix('tbl_');
// Now {{%users}} resolves to tbl_users in queries
$db->getTablePrefix(); // 'tbl_'

// app/Providers/AppServiceProvider.php
use Illuminate\Support\ServiceProvider;
use JustQuery\Driver\Mysql\Connection;
use JustQuery\Schema\Provider\{SchemaProvider, SchemaMode};

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(Connection::class, function ($app) {
            $pdo = $app['db']->connection()->getPdo();
            $db = Connection::fromPdo($pdo);

            $db->setSchemaProvider(new SchemaProvider(
                SchemaMode::JSON,
                jsonPath: base_path('database/schema/'),
            ));

            return $db;
        });
    }
}

use JustQuery\Driver\Mysql\Connection;
use JustQuery\Query\Query;

class UserController extends Controller
{
    public function index(Connection $db)
    {
        return (new Query($db))
            ->from('users')
            ->where(['status' => 'active'])
            ->all();
    }
}

// src/Factory/JustQueryFactory.php
namespace App\Factory;

use Doctrine\DBAL\Connection as DoctrineConnection;
use JustQuery\Driver\Mysql\Connection;

class JustQueryFactory
{
    public function __construct(private DoctrineConnection $doctrine) {}

    public function create(): Connection
    {
        return Connection::fromPdo(
            $this->doctrine->getNativeConnection(),
        );
    }
}

use JustQuery\Driver\Mysql\Connection;
use JustQuery\Query\Query;

class UserController extends AbstractController
{
    public function index(Connection $db): JsonResponse
    {
        $users = (new Query($db))
            ->from('users')
            ->where(['status' => 'active'])
            ->all();

        return $this->json($users);
    }
}

use JustQuery\Query\Query;

// SELECT
$users = (new Query($db))
    ->from('users')
    ->where(['status' => 'active'])
    ->orderBy(['created_at' => SORT_DESC])
    ->limit(10)
    ->all();

// INSERT
$db->createCommand()->insert('users', [
    'name' => 'John',
    'is_active' => true,
    'config' => ['role' => 'admin'],
])->execute();

// UPDATE
$db->createCommand()->update('users', ['name' => 'Jane'], ['id' => 1])->execute();

// DELETE
$db->createCommand()->delete('users', ['id' => 1])->execute();

// Create a Query from the connection
$query = $db->createQuery();

// Shorthand: create a Query with SELECT columns
$query = $db->select(['id', 'name'])->from('users');

// Create a raw command
$command = $db->createCommand('SELECT * FROM users WHERE id = :id', [':id' => 1]);

// Equality
$query->where(['status' => 'active']);
$query->where(['status' => null]);                // IS NULL

// Operators
$query->where(['>=', 'age', 18]);
$query->where(['between', 'age', 18, 65]);
$query->where(['like', 'name', 'John']);
$query->where(['in', 'id', [1, 2, 3]]);

// Logical
$query->where([
    'and',
    ['status' => 'active'],
    ['or', ['>', 'balance', 1000], ['role' => 'vip']],
]);

// Subquery in condition
$activeIds = (new Query($db))->select('id')->from('users')->where(['active' => 1]);
$query->where(['in', 'user_id', $activeIds]);

// EXISTS
$query->where(['exists', (new Query($db))->from('orders')->where('orders.user_id = users.id')]);

// JSON overlaps (MySQL)
$query->where(['json overlaps', 'tags', ['php', 'mysql']]);

// JSON contains — check if JSON column contains a value
$query->where(['json contains', 'options', 'en']);
$query->where(['json contains', 'options', ['role' => 'admin']]);
$query->where(['json contains', 'options', 'en', '$.languages']); // with path

// JSON length — compare length of JSON array/object
$query->where(['json length', 'tags', '>', 3]);
$query->where(['json length', 'data', '>=', 1, '$.items']); // with path

// Array overlaps (PostgreSQL)
$query->where(['array overlaps', 'tags', ['php', 'mysql']]);

// filterWhere — automatically ignores null/empty values
$query->filterWhere([
    'status' => $request->get('status'),   // skipped if null/empty
    'name'   => $request->get('name'),     // skipped if null/empty
]);

// Normal IN: SELECT * FROM users WHERE id IN (:qp0, :qp1, ... :qp9999)  — 10k bindings
// Raw IN:    SELECT * FROM users WHERE id IN (1, 2, 3, ... 10000)        — zero bindings

$userIds = [1, 2, 3, /* ... thousands of IDs */];

$query->from('users')
    ->whereIntegerInRaw('id', $userIds)
    ->all();

// NOT IN variant
$query->from('users')
    ->whereIntegerNotInRaw('id', $excludedIds)
    ->all();

$query->from('users')
    ->when($request->status, fn($q, $status) => $q->andWhere(['status' => $status]))
    ->when($request->sortBy, fn($q, $sort) => $q->orderBy($sort), fn($q) => $q->orderBy('id'))
    ->when($request->limit, fn($q, $limit) => $q->limit($limit));

$query->from('users')
    ->where(['status' => 'active'])
    ->andWhere(['>', 'age', 18])
    ->orWhere(['role' => 'admin']);

// Overwrite WHERE without exception
$query->setWhere(['status' => 'banned']);

// Useful for user-submitted filter forms
$query->from('products')
    ->where(['category' => 'electronics'])
    ->andFilterCompare('price', '>=100')   // price >= 100
    ->andFilterCompare('name', 'phone')    // name = 'phone'
    ->andFilterCompare('stock', '<>0');     // stock <> 0

// SELECT DISTINCT
$query->from('users')->distinct()->select('country');

// Add columns to existing SELECT
$query->select('id')->addSelect(['name', 'email']);

// MySQL-specific: SQL_CALC_FOUND_ROWS
$query->from('users')->select('*', 'SQL_CALC_FOUND_ROWS');
// or
$query->selectOption('SQL_CALC_FOUND_ROWS');

$query->from('orders o')
    ->innerJoin('users u', 'u.id = o.user_id')
    ->leftJoin('products p', 'p.id = o.product_id')
    ->rightJoin('categories c', 'c.id = p.category_id')
    ->where(['o.status' => 'confirmed']);

// Join with array condition (auto-quoted column names)
$query->innerJoin('users u', ['u.id' => 'o.user_id']);

$query->from('orders')
    ->select(['user_id', 'total' => 'SUM(amount)'])
    ->groupBy('user_id')
    ->addGroupBy('status')             // add to existing GROUP BY
    ->having(['>', 'SUM(amount)', 1000])
    ->andHaving(['status' => 'completed'])
    ->orHaving(['>', 'COUNT(*)', 5]);

// Overwrite HAVING
$query->setHaving(['>', 'SUM(amount)', 500]);

// Filter HAVING (ignores null/empty values)
$query->filterHaving(['status' => $userInput]);
$query->andFilterHaving(['category' => $category]);
$query->orFilterHaving(['region' => $region]);

$query->orderBy(['created_at' => SORT_DESC]);
$query->addOrderBy(['name' => SORT_ASC]);  // add to existing ORDER BY
$query->orderBy('created_at DESC, name ASC'); // string format

(new Query($db))->from('users')->count('*');
(new Query($db))->from('orders')->sum('total');
(new Query($db))->from('users')->average('age');
(new Query($db))->from('users')->min('age');
(new Query($db))->from('users')->max('age');

$query = (new Query($db))->from('users')->where(['status' => 'active']);

$rows = $query->all();           // All rows as array of arrays
$row = $query->one();            // First row or null
$exists = $query->exists();      // true if any rows match
$ids = $query->column();         // First column of all rows as flat array
$value = $query->scalar();       // Single value (first column, first row)

// Index results by the 'id' column
$users = (new Query($db))->from('users')->indexBy('id')->all();
// Result: [1 => ['id' => 1, 'name' => 'Alice'], 2 => ['id' => 2, 'name' => 'Bob']]

// Index by a closure
$users = (new Query($db))->from('users')
    ->indexBy(fn(array $row) => $row['email'])
    ->all();

$users = (new Query($db))
    ->from('users')
    ->resultCallback(function (array $rows): array {
        foreach ($rows as &$row) {
            $row['name'] = strtoupper($row['name']);
        }
        return $rows;
    })
    ->all();

$query->from('accounts')
    ->where(['id' => 1])
    ->for('UPDATE');

// Multiple FOR clauses
$query->for('UPDATE')->addFor('NOWAIT');

// Overwrite FOR clause
$query->setFor('SHARE');

$query->from('users')
    ->emulateExecution(true);

$query->all();    // returns []
$query->one();    // returns null
$query->exists(); // returns false
$query->count();  // returns 0

$query->shouldEmulateExecution(); // true

// In FROM
$sub = (new Query($db))->select('user_id, SUM(total) as total')->from('orders')->groupBy('user_id');
$query->from(['totals' => $sub])->where(['>', 'totals.total', 1000]);

// In SELECT
$query->select(['name', 'order_count' => (new Query($db))->select('COUNT(*)')->from('orders')->where('orders.user_id = users.id')]);

$cte = (new Query($db))
    ->select(['id', 'parent_id', 'name'])
    ->from('categories')
    ->where(['parent_id' => null]);

$query->withQuery($cte, 'tree', recursive: true)
    ->from('tree');

// Add more CTEs
$query->addWithQuery($anotherCte, 'summary');

$active = (new Query($db))->from('users')->where(['status' => 'active']);
$vip = (new Query($db))->from('users')->where(['role' => 'vip']);

$active->union($vip)->all();
$active->union($vip, all: true)->all(); // UNION ALL

foreach ((new Query($db))->from('users')->batch(1000) as $batch) {
    // $batch is an array of up to 1000 rows
}

foreach ((new Query($db))->from('users')->each() as $row) {
    // $row is a single row, fetched in batches internally
}

(new Query($db))->from('users')->where(['active' => false])
    ->chunkById(100, function (array $rows) use ($db) {
        foreach ($rows as $row) {
            $db->createCommand()->update('users', ['active' => true], ['id' => $row['id']])->execute();
        }
    });

// Custom primary key column
(new Query($db))->from('orders')->chunkById(500, $callback, 'order_id');

// Stop early by returning false
(new Query($db))->from('users')->chunkById(100, function (array $rows) {
    // process...
    return false; // stops after this chunk
});

// MySQL: INSERT ... ON DUPLICATE KEY UPDATE
// PostgreSQL: INSERT ... ON CONFLICT DO UPDATE
$db->createCommand()->upsert('users', [
    'email' => '[email protected]',
    'name' => 'John',
    'login_count' => new Expression('login_count + 1'),
])->execute();

// Increment a single column
$db->createCommand()->increment('users', 'login_count', 1, ['id' => 1])->execute();

// Increment with extra columns to update
$db->createCommand()->increment('users', 'balance', 50.00, ['id' => 1], ['last_deposit' => '2024-01-15'])->execute();

// Decrement
$db->createCommand()->decrement('products', 'stock', 1, ['id' => 5])->execute();

// Increment multiple columns at once
$db->createCommand()->incrementEach('users', ['votes' => 5, 'balance' => 100], ['id' => 1])->execute();

$db->createCommand()->insertBatch('users', [
    ['name' => 'Alice', 'email' => '[email protected]'],
    ['name' => 'Bob', 'email' => '[email protected]'],
])->execute();

use JustQuery\Expression\Value\Param;
use JustQuery\Constant\DataType;

$query->from('users')
    ->where('status = :status')
    ->params([':status' => 'active'])
    ->addParams([':role' => 'admin']);

// On commands with explicit type
$command = $db->createCommand('SELECT * FROM users WHERE id = :id');
$command->bindValue(':id', 42, DataType::INTEGER);
$command->bindValues([':name' => 'John', ':profile' => new Param($blob, DataType::LOB)]);

// Raw SQL
$row = $db->createCommand('SELECT * FROM users WHERE id = :id', [':id' => 1])->queryOne();

// Direct command query methods
$command = $db->createCommand('SELECT * FROM users');
$rows = $command->queryAll();       // All rows
$row = $command->queryOne();        // First row
$column = $command->queryColumn();  // First column as flat array
$value = $command->queryScalar();   // Single value

// SQL access
$command->getSql();     // The SQL with placeholders
$command->getRawSql();  // SQL with values inserted (for logging)
$command->setSql($sql); // Set new SQL (with quoting)
$command->setRawSql($sql); // Set SQL without modification

// Execute non-query (INSERT, UPDATE, DELETE)
$affectedRows = $command->execute();

// Automatic transaction with closure
$result = $db->transaction(function (ConnectionInterface $db) {
    $db->createCommand()->insert('orders', ['user_id' => 1, 'total' => 99.99])->execute();
    $db->createCommand()->update('users', ['order_count' => new Expression('order_count + 1')], ['id' => 1])->execute();
    return $db->getLastInsertId();
});

// Manual transaction
$transaction = $db->beginTransaction();
try {
    $db->createCommand()->insert('orders', ['total' => 50])->execute();
    $transaction->commit();
} catch (\Throwable $e) {
    $transaction->rollBack();
    throw $e;
}

// Check active transaction
$tx = $db->getTransaction(); // null if none active

// Savepoints
$db->setEnableSavepoint(true);
$db->isSavepointEnabled(); // true

$command = $db->createCommand('INSERT INTO orders ...');
$command->setRetryHandler(function (\JustQuery\Exception\Exception $e, int $attempt): bool {
    // $attempt starts at 1
    if ($attempt > 3) {
        return false; // give up, throw the exception
    }
    // Retry on deadlock (MySQL error 1213)
    return str_contains($e->getMessage(), 'Deadlock');
});
$command->execute();

// Force the optimizer to use a specific index
$query->from('users')
    ->forceIndex('users', 'idx_email')
    ->where(['email' => $email]);

// Suggest indexes (optimizer may still ignore)
$query->from('users')
    ->useIndex('users', ['idx_email', 'idx_status']);

// Prevent the optimizer from using an index
$query->from('users')
    ->ignoreIndex('users', 'idx_created_at');

// Multiple hints on the same table
$query->from('users')
    ->forceIndex('users', 'idx_email')
    ->ignoreIndex('users', 'idx_old_status');

// Hints on JOIN tables
$query->from('users')
    ->innerJoin('orders', 'users.id = orders.user_id')
    ->forceIndex('orders', 'idx_user_id');

// Works with aliases
$query->from(['u' => 'users'])
    ->forceIndex('users', 'idx_email')
    ->where(['u.email' => $email]);

use JustQuery\Expression\Expression;

$query->select([new Expression('COUNT(DISTINCT user_id) as unique_users')]);
$query->where(new Expression('DATE(created_at) = CURDATE()'));

use JustQuery\Expression\Statement\CaseX;
use JustQuery\Expression\Statement\WhenThen;

$case = new CaseX(
    new WhenThen(['status' => 'active'], 'Active'),
    new WhenThen(['status' => 'banned'], 'Banned'),
    else: 'Unknown',
);
$query->select(['name', 'label' => $case]);

use JustQuery\Expression\Function\Greatest;
use JustQuery\Expression\Function\Least;
use JustQuery\Expression\Function\Length;
use JustQuery\Expression\Function\Longest;
use JustQuery\Expression\Function\Shortest;

// GREATEST / LEAST — returns max/min of multiple columns
$query->select([new Greatest('col1', 'col2', 'col3')]);
$query->select([new Least('price', 'sale_price')]);

// LENGTH — string length of a column
$query->select(['name', 'name_len' => new Length('name')]);

// LONGEST / SHORTEST — returns the longest/shortest string among columns
$query->select([new Longest('first_name', 'last_name')]);
$query->select([new Shortest('city', 'state')]);

use JustQuery\Expression\Value\JsonValue;
use JustQuery\Expression\Value\Value;
use JustQuery\Expression\Value\Param;
use JustQuery\Expression\Value\ColumnName;
use JustQuery\Expression\Value\DateTimeValue;
use JustQuery\Constant\DataType;

// JSON — encodes PHP array as JSON for the database
$query->where(['config' => new JsonValue(['role' => 'admin'])]);

// Value — wrap a raw PHP value for type-safe binding
$query->where(['=', 'score', new Value(42)]);

// Param — bind with explicit PDO data type
$query->where(['=', 'avatar', new Param($binaryData, DataType::LOB)]);

// ColumnName — reference a column name as an expression
$query->select([new ColumnName('users.name')]);

// DateTimeValue — bind DateTime objects
$query->where(['>=', 'created_at', new DateTimeValue(new \DateTimeImmutable('2024-01-01'))]);

use JustQuery\Expression\CompositeExpression;

// Group multiple expressions into one
$composite = new CompositeExpression('AND', [
    new Expression('age > 18'),
    new Expression('status = 1'),
]);

use JustQuery\Schema\Provider\{SchemaProvider, SchemaMode};

// DISABLED — pure query builder, no type casting
$provider = new SchemaProvider(SchemaMode::DISABLED);

// JSON — read from JSON files, zero DB overhead, deploy-safe
$provider = new SchemaProvider(SchemaMode::JSON, jsonPath: '/path/to/schema/');

// CACHE — read from DB, cache in Redis/APCu (traditional approach)
$provider = new SchemaProvider(SchemaMode::CACHE, dbSchema: $schema);

// JSON_CACHE — JSON first, DB+cache fallback for unknown tables
$provider = new SchemaProvider(SchemaMode::JSON_CACHE, dbSchema: $schema, jsonPath: '/path/to/schema/');

$row = $query->from('users')->where(['id' => 1])->withTypecasting()->one();

$row['id'];        // int(1)         — not string("1")
$row['is_active']; // bool(true)     — not string("1")
$row['balance'];   // float(1500.5)  — not string("1500.50")
$row['options'];   // array(...)     — not string('{"role":"admin"}')

// Enable type casting only when reading from DB
$command = $db->createCommand('SELECT * FROM users');
$command = $command->withPhpTypecasting();  // cast DB → PHP on reads

// Enable type casting only when writing to DB
$command = $command->withDbTypecasting();   // cast PHP → DB on inserts/updates

// Enable both at once
$command = $command->withTypecasting();

// On Query objects
$query = (new Query($db))->from('users')->withTypecasting();

// Schema: score is GENERATED ALWAYS AS (reviews_sum / reviews_count)
$db->createCommand()->insert('products', [
    'name' => 'Widget',
    'price' => 9.99,
    'score' => 4.5,  // silently excluded — won't cause a MySQL error
])->execute();

use JustQuery\Profiler\QueryProfiler;

$profiler = new QueryProfiler();
$connection->setProfiler($profiler);

// ... run queries ...

$profiler->getCount();          // 47
$profiler->getTotalTime();      // 123.45 (ms)
$profiler->getSlowest(5);       // top 5 slowest queries
$profiler->getErrors();         // queries that threw exceptions
$profiler->getQueries();        // all queries: sql, time, params, error
$profiler->reset();             // clear collected data

// INSERT and return primary key values
$pks = $db->createCommand()->insertReturningPks('users', ['name' => 'John', 'email' => '[email protected]']);
// ['id' => 42]

// UPSERT and return specific columns
$row = $db->createCommand()->upsertReturning('users', $columns, true, ['id', 'name', 'email']);
// ['id' => 42, 'name' => 'John', 'email' => '[email protected]']

// UPSERT and return just primary keys
$pks = $db->createCommand()->upsertReturningPks('users', $columns, true);
// ['id' => 42]

use JustQuery\Expression\Value\ArrayValue;

// ARRAY[1, 2, 3]::integer[]
$query->where(['=', 'ids', new ArrayValue([1, 2, 3], 'integer')]);

use JustQuery\Expression\Value\StructuredValue;

// ROW(10, 'USD')::money_type
$query->where(['=', 'price', new StructuredValue(['amount' => 10, 'currency' => 'USD'], 'money_type')]);

use JustQuery\Driver\Pgsql\Expression\Int4RangeValue;
use JustQuery\Driver\Pgsql\Expression\DateRangeValue;

// int4range '[1, 10)'
new Int4RangeValue(1, 10);

// daterange '[2024-01-01, 2024-12-31]'
new DateRangeValue(new DateTimeImmutable('2024-01-01'), new DateTimeImmutable('2024-12-31'));

use JustQuery\Expression\Function\ArrayMerge;

// Merge PostgreSQL arrays
$query->select([new ArrayMerge('tags1', 'tags2')]);

// CREATE INDEX ... USING GIN
$db->createCommand()->createIndex('users', 'idx_tags', 'tags', indexMethod: 'gin')->execute();

// Via Command (executes immediately)
$cmd = $db->createCommand();

// Via QueryBuilder (returns SQL string)
$qb = $db->getQueryBuilder();

$cmd->createTable('users', [
    'id' => ColumnBuilder::primaryKey(),
    'name' => ColumnBuilder::string(255)->notNull(),
    'email' => ColumnBuilder::string(255)->unique(),
    'balance' => ColumnBuilder::decimal(10, 2)->defaultValue(0),
])->execute();

$cmd->dropTable('users')->execute();
$cmd->dropTable('users', ifExists: true, cascade: true)->execute();
$cmd->renameTable('users', 'accounts')->execute();
$cmd->truncateTable('users')->execute();

$cmd->addColumn('users', 'age', ColumnBuilder::integer())->execute();
$cmd->alterColumn('users', 'name', ColumnBuilder::string(500))->execute();
$cmd->dropColumn('users', 'age')->execute();
$cmd->renameColumn('users', 'name', 'full_name')->execute();

$cmd->createIndex('users', 'idx_email', 'email', indexType: 'UNIQUE')->execute();
$cmd->createIndex('users', 'idx_tags', 'tags', indexMethod: 'gin')->execute(); // PostgreSQL GIN
$cmd->dropIndex('users', 'idx_email')->execute();

$cmd->addForeignKey('orders', 'fk_user', 'user_id', 'users', 'id', 'CASCADE', 'CASCADE')->execute();
$cmd->dropForeignKey('orders', 'fk_user')->execute();

$cmd->addPrimaryKey('users', 'pk_users', 'id')->execute();
$cmd->dropPrimaryKey('users', 'pk_users')->execute();
$cmd->addUnique('users', 'uq_email', 'email')->execute();
$cmd->dropUnique('users', 'uq_email')->execute();
$cmd->addCheck('users', 'ck_age', 'age >= 0')->execute();
$cmd->dropCheck('users', 'ck_age')->execute();
$cmd->addDefaultValue('users', 'df_status', 'status', 'active')->execute();
$cmd->dropDefaultValue('users', 'df_status')->execute();

$cmd->addCommentOnTable('users', 'Main user accounts table')->execute();
$cmd->addCommentOnColumn('users', 'balance', 'Account balance in cents')->execute();
$cmd->dropCommentFromTable('users')->execute();
$cmd->dropCommentFromColumn('users', 'balance')->execute();

$cmd->createView('active_users', (new Query($db))->from('users')->where(['status' => 'active']))->execute();
$cmd->dropView('active_users')->execute();

// Reset auto-increment sequence
$cmd->resetSequence('users', 100)->execute(); // Next ID will be 100
$cmd->resetSequence('users')->execute();       // Next ID = max(id) + 1

// Disable/enable foreign key checks (useful for migrations)
$cmd->checkIntegrity('', 'users', false)->execute(); // Disable
$cmd->checkIntegrity('', 'users', true)->execute();  // Enable

// List all databases
$databases = $cmd->showDatabases(); // ['myapp', 'information_schema', ...]