Skip to content

Commit 5e3ba99

Browse files
committed
Connect/PHP: Reorganize section. Each item gets a dedicated page.
1 parent a4f89a0 commit 5e3ba99

File tree

8 files changed

+170
-129
lines changed

8 files changed

+170
-129
lines changed

docs/connect/drivers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ For connecting to CrateDB from PHP.
279279
```
280280
```{sd-item}
281281
[![](https://img.shields.io/github/v/tag/crate/crate-pdo?label=latest)](https://github.com/crate/crate-pdo)
282-
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#php)
282+
[![](https://img.shields.io/badge/example-snippet-darkcyan)](#connect-php)
283283
```
284284
:::
285285

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

docs/connect/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ application
178178
179179
java
180180
javascript
181-
php
181+
php/index
182182
python
183183
ruby
184184
natural

docs/connect/php.md

Lines changed: 0 additions & 126 deletions
This file was deleted.

docs/connect/php/amphp.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
(amphp)=
2+
3+
# AMPHP PostgreSQL
4+
5+
:::{div} .float-right .text-right
6+
[![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)
7+
:::
8+
:::{div} .clearfix
9+
:::
10+
11+
The [AMPHP PostgreSQL driver], `amphp/postgres`, is an asynchronous
12+
PostgreSQL client based on Amp.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
```php
17+
<?php
18+
require 'vendor/autoload.php';
19+
20+
use Amp\Postgres\PostgresConfig;
21+
use Amp\Postgres\PostgresConnectionPool;
22+
use function Amp\async;
23+
use function Amp\Future\await;
24+
25+
await(async(function () {
26+
$config = PostgresConfig::fromString("host=localhost user=crate");
27+
$pool = new PostgresConnectionPool($config);
28+
$statement = $pool->prepare("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
29+
$result = $statement->execute();
30+
foreach ($result as $row) {
31+
print_r($row);
32+
}
33+
}));
34+
?>
35+
```
36+
:::{rubric} Example
37+
:::
38+
- [Connect to CrateDB and CrateDB Cloud using AMPHP/PostgreSQL]
39+
40+
41+
[AMPHP PostgreSQL driver]: https://github.com/amphp/postgres
42+
[Connect to CrateDB and CrateDB Cloud using AMPHP/PostgreSQL]: https://github.com/crate/cratedb-examples/tree/main/by-language/php-amphp

docs/connect/php/crate-dbal.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
(crate-dbal)=
2+
3+
# CrateDB DBAL
4+
5+
:::{div} .float-right .text-right
6+
[![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)
7+
:::
8+
:::{div} .clearfix
9+
:::
10+
11+
DBAL is a PHP database abstraction layer that comes with database schema
12+
introspection, schema management, and PDO support.
13+
The {ref}`crate-dbal:index`, `crate/crate-dbal`, implements this specification,
14+
wrapping access to CrateDB's HTTP interface.
15+
:::{warning}
16+
The adapter currently does not support recent versions of the Doctrine ORM,
17+
see [Add support for Doctrine 3] and [Add support for Doctrine 4]. Both
18+
patches currently stalled, so please explicitly let us know if you have
19+
any need for corresponding support.
20+
:::
21+
22+
:::{rubric} Synopsis
23+
:::
24+
```php
25+
<?php
26+
require 'vendor/autoload.php';
27+
28+
$params = array(
29+
'driverClass' => 'Crate\DBAL\Driver\PDOCrate\Driver',
30+
'user' => 'admin',
31+
'password' => '<PASSWORD>',
32+
'host' => '<name-of-your-cluster>.cratedb.net',
33+
'port' => 4200
34+
);
35+
36+
$connection = \Doctrine\DBAL\DriverManager::getConnection($params);
37+
$sql = "SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3";
38+
$result = $connection->query($sql)->fetch();
39+
40+
print_r($result);
41+
?>
42+
```
43+
44+
45+
[Add support for Doctrine 3]: https://github.com/crate/crate-dbal/pull/122
46+
[Add support for Doctrine 4]: https://github.com/crate/crate-dbal/pull/136

docs/connect/php/crate-pdo.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(crate-pdo)=
2+
3+
# CrateDB PDO
4+
5+
:::{div} .float-right .text-right
6+
[![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)
7+
:::
8+
:::{div} .clearfix
9+
:::
10+
11+
The PHP Data Objects (PDO) is a standard PHP extension that defines a common
12+
interface for accessing databases in PHP.
13+
The {ref}`crate-pdo:index`, `crate/crate-pdo`, implements this specification,
14+
wrapping access to CrateDB's HTTP interface.
15+
16+
:::{rubric} Synopsis
17+
:::
18+
```php
19+
<?php
20+
require 'vendor/autoload.php';
21+
22+
use Crate\PDO\PDOCrateDB;
23+
24+
$dsn = '<DATA_SOURCE_NAME>';
25+
$user = 'crate';
26+
$password = null;
27+
$options = null;
28+
$connection = new PDOCrateDB($dsn, $user, $password, $options);
29+
30+
$stm = $connection->query("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
31+
$result = $stm->fetch();
32+
print_r($result);
33+
?>
34+
```

docs/connect/php/index.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
(connect-php)=
2+
3+
# PHP
4+
5+
:::{div} sd-text-muted
6+
Connect to CrateDB and CrateDB Cloud from PHP.
7+
:::
8+
9+
:::{toctree}
10+
:maxdepth: 1
11+
amphp
12+
pdo-pgsql
13+
crate-pdo
14+
crate-dbal
15+
:::

docs/connect/php/pdo-pgsql.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
(pdo-pgsql)=
2+
3+
# PostgreSQL PDO
4+
5+
:::{div} .float-right .text-right
6+
[![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)
7+
:::
8+
:::{div} .clearfix
9+
:::
10+
11+
[PDO_PGSQL] is a PHP-native driver that implements the PHP Data Objects (PDO)
12+
interface, which enables access from PHP to PostgreSQL databases.
13+
14+
:::{rubric} Synopsis
15+
:::
16+
```php
17+
<?php
18+
$connection = new PDO("pgsql:host=localhost;port=5432;user=crate");
19+
$cursor = $connection->query("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
20+
print_r($cursor->fetchAll(PDO::FETCH_ASSOC));
21+
?>
22+
```
23+
24+
:::{rubric} Example
25+
:::
26+
- [Use the PDO_PGSQL driver with CrateDB]
27+
28+
29+
[PDO_PGSQL]: https://www.php.net/manual/en/ref.pdo-pgsql.php
30+
[Use the PDO_PGSQL driver with CrateDB]: https://github.com/crate/cratedb-examples/tree/main/by-language/php-pdo

0 commit comments

Comments
 (0)