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