Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/connect/drivers.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ For connecting to CrateDB from PHP.
```
```{sd-item}
[![](https://img.shields.io/github/v/tag/crate/crate-pdo?label=latest)](https://github.com/crate/crate-pdo)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#php)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#connect-php)
```
:::

Expand All @@ -294,7 +294,7 @@ For connecting to CrateDB from PHP, using DBAL and Doctrine.
```
```{sd-item}
[![](https://img.shields.io/github/v/tag/crate/crate-dbal?label=latest)](https://github.com/crate/crate-dbal)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#php)
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#connect-php)
```
:::

Expand Down
2 changes: 1 addition & 1 deletion docs/connect/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ application

java
javascript
php
php/index
python
ruby
natural
Expand Down
67 changes: 0 additions & 67 deletions docs/connect/php.md

This file was deleted.

42 changes: 42 additions & 0 deletions docs/connect/php/amphp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
(amphp)=

# AMPHP PostgreSQL

:::{div} .float-right .text-right
[![PHP AMPHP CI](https://github.com/crate/cratedb-examples/actions/workflows/lang-php-amphp.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-php-amphp.yml)
:::
:::{div} .clearfix
:::

The [AMPHP PostgreSQL driver], `amphp/postgres`, is an asynchronous
PostgreSQL client based on Amp.

:::{rubric} Synopsis
:::
```php
<?php
require 'vendor/autoload.php';

use Amp\Postgres\PostgresConfig;
use Amp\Postgres\PostgresConnectionPool;
use function Amp\async;
use function Amp\Future\await;

await(async(function () {
$config = PostgresConfig::fromString("host=localhost user=crate");
$pool = new PostgresConnectionPool($config);
$statement = $pool->prepare("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
$result = $statement->execute();
foreach ($result as $row) {
print_r($row);
}
}));
?>
```
:::{rubric} Example
:::
- [Connect to CrateDB and CrateDB Cloud using AMPHP/PostgreSQL]


[AMPHP PostgreSQL driver]: https://github.com/amphp/postgres
[Connect to CrateDB and CrateDB Cloud using AMPHP/PostgreSQL]: https://github.com/crate/cratedb-examples/tree/main/by-language/php-amphp
46 changes: 46 additions & 0 deletions docs/connect/php/crate-dbal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
(crate-dbal)=

# CrateDB DBAL

:::{div} .float-right .text-right
[![crate-dbal CI](https://github.com/crate/crate-dbal/actions/workflows/tests.yml/badge.svg)](https://github.com/crate/crate-dbal/actions/workflows/tests.yml)
:::
:::{div} .clearfix
:::

DBAL is a PHP database abstraction layer that comes with database schema
introspection, schema management, and PDO support.
The {ref}`crate-dbal:index`, `crate/crate-dbal`, implements this specification,
wrapping access to CrateDB's HTTP interface.
:::{warning}
The adapter currently does not support recent versions of the Doctrine ORM,
see [Add support for Doctrine 3] and [Add support for Doctrine 4]. Both
patches currently stalled, so please explicitly let us know if you have
any need for corresponding support.
:::

:::{rubric} Synopsis
:::
```php
<?php
require 'vendor/autoload.php';

$params = array(
'driverClass' => 'Crate\DBAL\Driver\PDOCrate\Driver',
'user' => 'admin',
'password' => '<PASSWORD>',
'host' => '<name-of-your-cluster>.cratedb.net',
'port' => 4200
);

$connection = \Doctrine\DBAL\DriverManager::getConnection($params);
$sql = "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3";
$result = $connection->query($sql)->fetch();

print_r($result);
?>
```


[Add support for Doctrine 3]: https://github.com/crate/crate-dbal/pull/122
[Add support for Doctrine 4]: https://github.com/crate/crate-dbal/pull/136
34 changes: 34 additions & 0 deletions docs/connect/php/crate-pdo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(crate-pdo)=

# CrateDB PDO

:::{div} .float-right .text-right
[![crate-pdo CI](https://github.com/crate/crate-pdo/actions/workflows/tests.yml/badge.svg)](https://github.com/crate/crate-pdo/actions/workflows/tests.yml)
:::
:::{div} .clearfix
:::

The PHP Data Objects (PDO) is a standard PHP extension that defines a common
interface for accessing databases in PHP.
The {ref}`crate-pdo:index`, `crate/crate-pdo`, implements this specification,
wrapping access to CrateDB's HTTP interface.

:::{rubric} Synopsis
:::
```php
<?php
require 'vendor/autoload.php';

use Crate\PDO\PDOCrateDB;

$dsn = '<DATA_SOURCE_NAME>';
$user = 'crate';
$password = null;
$options = null;
$connection = new PDOCrateDB($dsn, $user, $password, $options);

$stm = $connection->query("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
$result = $stm->fetch();
print_r($result);
?>
```
15 changes: 15 additions & 0 deletions docs/connect/php/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
(connect-php)=

# PHP

:::{div} sd-text-muted
Connect to CrateDB and CrateDB Cloud from PHP.
:::

:::{toctree}
:maxdepth: 1
amphp
pdo-pgsql
crate-pdo
crate-dbal
:::
30 changes: 30 additions & 0 deletions docs/connect/php/pdo-pgsql.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
(pdo-pgsql)=

# PostgreSQL PDO

:::{div} .float-right .text-right
[![PHP PDO CI](https://github.com/crate/cratedb-examples/actions/workflows/lang-php-pdo.yml/badge.svg)](https://github.com/crate/cratedb-examples/actions/workflows/lang-php-pdo.yml)
:::
:::{div} .clearfix
:::

[PDO_PGSQL] is a PHP-native driver that implements the PHP Data Objects (PDO)
interface, which enables access from PHP to PostgreSQL databases.

:::{rubric} Synopsis
:::
```php
<?php
$connection = new PDO("pgsql:host=localhost;port=5432;user=crate");
$cursor = $connection->query("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
print_r($cursor->fetchAll(PDO::FETCH_ASSOC));
?>
```

:::{rubric} Example
:::
- [Use the PDO_PGSQL driver with CrateDB]


[PDO_PGSQL]: https://www.php.net/manual/en/ref.pdo-pgsql.php
[Use the PDO_PGSQL driver with CrateDB]: https://github.com/crate/cratedb-examples/tree/main/by-language/php-pdo