1
1
Cassandra client library for PHP
2
2
================================
3
3
4
- <a href =" https://codeclimate.com/github/duoshuo/php-cassandra/ " ><img src =" https://codeclimate.com/github/duoshuo/php-cassandra.png " /></a >
5
- <a href =" https://scrutinizer-ci.com/g/duoshuo/php-cassandra/ " ><img src =" https://scrutinizer-ci.com/g/duoshuo/php-cassandra/badges/quality-score.png?b=master " /></a >
6
- <a href =" https://scrutinizer-ci.com/g/duoshuo/php-cassandra/ " ><img src =" https://scrutinizer-ci.com/g/duoshuo/php-cassandra/badges/build.png?b=master " /></a >
7
-
8
- Cassandra client library for PHP, which support Protocol v3 (Cassandra 2.1) and asynchronous request
4
+ Cassandra client library for PHP, which supports Protocol v5 (Cassandra 4.x) and asynchronous requests.
9
5
10
6
## Features
11
- * Using Protocol v3 (Cassandra 2.1 )
7
+ * Using Protocol v5 (Cassandra 4.x )
12
8
* Support ssl/tls with stream transport layer
13
9
* Support asynchronous and synchronous request
14
10
* Support for logged, unlogged and counter batches
@@ -23,7 +19,7 @@ Cassandra client library for PHP, which support Protocol v3 (Cassandra 2.1) and
23
19
24
20
## Installation
25
21
26
- PHP 5.4 + is required. There is no need for additional libraries.
22
+ PHP 8.1 + is required. There is no need for additional libraries.
27
23
28
24
If you want to use Bigint or Timestamp type, 64-bit system is required.
29
25
@@ -69,12 +65,14 @@ $nodes = [
69
65
'timeout' => 30, // write/recv timeout, default 30, stream transport only
70
66
'persistent' => true, // use persistent PHP connection, default false, stream transport only
71
67
],
72
- [ // advanced way, using SSL
68
+ [ // advanced way, using SSL/TLS
73
69
'class' => 'Cassandra\Connection\Stream', // "class" must be defined as "Cassandra\Connection\Stream" for ssl or tls
74
70
'host' => 'ssl://10.205.48.70',// or 'tls://10.205.48.70'
75
71
'port' => 9042,
76
72
'username' => 'admin',
77
73
'password' => 'pass',
74
+ 'ssl' => ['verify_peer' => false, 'verify_peer_name' => false], //disable certificate verification
75
+ //'ssl' => ['cafile' => 'cassandra.pem', 'verify_peer_name'=>false] //with SSL certificate validation, no name check
78
76
],
79
77
];
80
78
@@ -125,6 +123,16 @@ $row = $response->fetchRow(); // ArrayObject
125
123
$value = $response->fetchOne(); // mixed
126
124
```
127
125
126
+ ## Iterate over result
127
+ ``` php
128
+ // Print all roles
129
+ $response = $connection->querySync("SELECT role FROM system_auth.roles");
130
+ foreach($response AS $rowNo => $rowContent)
131
+ {
132
+ echo $rowContent['role']."\n";
133
+ }
134
+ ```
135
+
128
136
## Query Asynchronously
129
137
130
138
``` php
@@ -221,20 +229,33 @@ All types are supported.
221
229
// Counter
222
230
new Cassandra\Type\Counter(1000);
223
231
232
+ // Date (a number of days +- since January 1st, 1970)
233
+ new Cassandra\Type\Date(19435);
234
+ new Cassandra\Type\Date(-2000);
235
+
224
236
// Decimal
225
237
new Cassandra\Type\Decimal('0.0123');
226
238
227
239
// Double
228
240
new Cassandra\Type\Double(2.718281828459);
229
241
242
+ // Duration
243
+ new Cassandra\Type\Duration(['months' => 1, 'days' => 2, 'nanoseconds'=> 3]);
244
+
230
245
// Float
231
246
new Cassandra\Type\PhpFloat(2.718);
232
247
233
248
// Inet
234
249
new Cassandra\Type\Inet('127.0.0.1');
235
250
236
251
// Int
237
- new Cassandra\Type\PhpInt(1);
252
+ new Cassandra\Type\PhpInt(12345678);
253
+
254
+ // Smallint
255
+ new Cassandra\Type\Smallint(2048);
256
+
257
+ // Tinyint
258
+ new Cassandra\Type\Tinyint(122);
238
259
239
260
// CollectionList
240
261
new Cassandra\Type\CollectionList([1, 1, 1], [Cassandra\Type\Base::INT]);
@@ -245,6 +266,9 @@ All types are supported.
245
266
// CollectionSet
246
267
new Cassandra\Type\CollectionSet([1, 2, 3], [Cassandra\Type\Base::INT]);
247
268
269
+ // Time (nanoseconds since midnight)
270
+ new Cassandra\Type\Time(18000000000000);
271
+
248
272
// Timestamp (unit: millisecond)
249
273
new Cassandra\Type\Timestamp((int) (microtime(true) * 1000));
250
274
new Cassandra\Type\Timestamp(1409830696263);
@@ -322,5 +346,12 @@ new Cassandra\Type\CollectionSet([
322
346
* [ shen2/cadmin] ( https://github.com/shen2/cadmin ) : Web admin panel for Cassandra, like phpmyadmin
323
347
324
348
## Inspired by
349
+ * [ duoshuo/php-cassandra] ( https://github.com/duoshuo/php-cassandra )
325
350
* [ mauritsl/php-cassandra] ( https://github.com/mauritsl/php-cassandra )
326
351
* [ evseevnn/php-cassandra-binary] ( https://github.com/evseevnn/php-cassandra-binary )
352
+
353
+ ## Merged contributions for duoshuo/php-cassandra
354
+ * https://github.com/arnaud-lb/php-cassandra/commit/b6444ee5f8f7079d7df80de85201b11f77e0d376
355
+ * https://github.com/duoshuo/php-cassandra/pull/78
356
+ * https://github.com/duoshuo/php-cassandra/pull/77
357
+ * https://github.com/duoshuo/php-cassandra/pull/66
0 commit comments