CrateDB PDO DriverΒΆ
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. The CrateDB PDO driver provides a PDO adapter to the HTTP interface of CrateDB.
Synopsis
composer require crate/crate-pdo
<?php
require 'vendor/autoload.php';
use Crate\PDO\PDOCrateDB;
use PDO;
$dsn = 'crate:localhost:4200';
$username = 'crate';
$password = 'crate';
$options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC];
$pdo = new PDOCrateDB(
$dsn,
$username,
$password,
$options,
);
$stm = $pdo->query('SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3');
while ($row = $stm->fetch()) {
print_r($row);
}
?>
Synopsis (SSL)
Enable SSL, for example when connecting to CrateDB Cloud.
$dsn = 'crate:clustername.cratedb.net:4200';
$pdo->setAttribute(PDOCrateDB::CRATE_ATTR_SSL_MODE, PDOCrateDB::CRATE_ATTR_SSL_MODE_REQUIRED);
Documentation
See also
The CrateDB PDO example application demonstrates the use of the CrateDB PDO driver.
An alternative to the HTTP driver is to use the PostgreSQL PDO Driver, demonstrated at PostgreSQL PDO example application.