You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$statement = $pool->prepare("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
26
+
27
+
$result = $statement->execute();
28
+
foreach ($result as $row) {
29
+
print_r($row);
30
+
}
31
+
?>
32
+
```
33
+
:::{rubric} Example
34
+
:::
35
+
-[Connect to CrateDB and CrateDB Cloud using AMPHP/PostgreSQL] [](https://github.com/crate/cratedb-examples/actions/workflows/lang-php-amphp.yml)
36
+
37
+
## PostgreSQL PDO driver
38
+
39
+
[PDO_PGSQL] is a PHP-native driver that implements the PHP Data Objects (PDO)
40
+
interface to enable access from PHP to PostgreSQL databases.
41
+
42
+
:::{rubric} Synopsis
43
+
:::
44
+
```php
45
+
<?php
46
+
$connection = new PDO("pgsql:host=localhost;port=5432;user=crate");
47
+
$cursor = $connection->query("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
48
+
print_r($cursor->fetchAll(PDO::FETCH_ASSOC));
49
+
?>
50
+
```
51
+
52
+
:::{rubric} Example
53
+
:::
54
+
-[Use the PDO_PGSQL driver with CrateDB] [](https://github.com/crate/cratedb-examples/actions/workflows/lang-php-pdo.yml)
55
+
56
+
## CrateDB PDO driver
10
57
11
58
The PHP Data Objects (PDO) is a standard PHP extension that defines a common
12
59
interface for accessing databases in PHP.
60
+
The {ref}`crate-pdo:index` implements this specification, wrapping access to
61
+
CrateDB's HTTP interface.
13
62
14
-
Example implementation will look like this:
15
-
63
+
:::{rubric} Synopsis
64
+
:::
16
65
```php
17
66
<?php
18
67
19
68
require 'vendor/autoload.php';
20
69
21
-
use Crate\PDO\PDO as PDO;
22
-
23
-
$pdo = new PDO(
24
-
'crate:<name-of-your-cluster>.cratedb.net:4200',
25
-
'admin',
26
-
'<PASSWORD>'
27
-
);
70
+
use Crate\PDO\PDOCrateDB;
28
71
29
-
$stm = $pdo->query('SELECT name FROM sys.cluster');
30
-
$name = $stm->fetch();
31
-
print $name[0];
72
+
$dsn = '<DATA_SOURCE_NAME>';
73
+
$user = 'crate';
74
+
$password = null;
75
+
$options = null;
76
+
$connection = new PDOCrateDB($dsn, $user, $password, $options);
32
77
78
+
$stm = $connection->query("SELECT * FROM sys.summits ORDER BY height DESC LIMIT 3");
79
+
$result = $stm->fetch();
80
+
print_r($result);
33
81
?>
34
82
```
35
83
36
-
See full documentation {ref}`here <crate-pdo:index>`.
0 commit comments