The Guide for Time Series Data Projects is out.

Download now
Skip to content

How to Connect with PHP

Enable seamless PHP to CrateDB integration with diverse drivers.


Connecting to CrateDB with PHP offers various drivers, such as DBAL and PDO, each presenting distinct functionalities to suit different development requirements. These drivers facilitate seamless integration between PHP applications and CrateDB, providing versatile options for developers to establish connections and interact with the database.



require 'vendor/autoload.php';

use Crate\PDO\PDO as PDO;

$pdo = new PDO(

$stm = $pdo->query('SELECT name FROM sys.cluster');
$name = $stm->fetch();
print $name[0];



require 'vendor/autoload.php';

$params = array(
    'driverClass' => 'Crate\DBAL\Driver\PDOCrate\Driver',
    'user' => 'admin',
    'password' = '',
    'host' => '',
    'port' => 4200

$connection = \Doctrine\DBAL\DriverManager::getConnection($params);
$sql = 'SELECT name FROM sys.cluster';
$name = $connection->query($sql)->fetch();

print $name['name'];


The DBAL driver for CrateDB, built on the PHP database abstraction layer, provides essential functionalities for schema management and interaction with CrateDB. It offers compatibility with Doctrine ORM, simplifying Object-Relational Mapping for PHP developers. 

The PDO driver for CrateDB, following the PHP Data Objects standard, offers a flexible and standard interface for database access in PHP, including connection possibilities to CrateDB and CrateDB Cloud.

Additional resources