PHPackages                             slicingdice/slicingdice - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. slicingdice/slicingdice

ActiveLibrary[Database &amp; ORM](/categories/database)

slicingdice/slicingdice
=======================

Official PHP client for SlicingDice, Data Warehouse and Analytics Database as a Service.

v2.0.2(8y ago)437MITPHPPHP &gt;=5.2.8

Since Apr 7Pushed 7y ago2 watchersCompare

[ Source](https://github.com/SlicingDice/slicingdice-php)[ Packagist](https://packagist.org/packages/slicingdice/slicingdice)[ Docs](https://github.com/SlicingDice/slicingdice-php)[ RSS](/packages/slicingdice-slicingdice/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

SlicingDice Official PHP Client (v2.1.0)
========================================

[](#slicingdice-official-php-client-v210)

Official PHP client for [SlicingDice - Data Warehouse and Analytics Database as a Service](https://www.slicingdice.com/).

[SlicingDice](http://www.slicingdice.com/) is a serverless, SQL &amp; API-based, easy-to-use and really cost-effective alternative to Amazon Redshift and Google BigQuery.

### Build Status: [![CircleCI](https://camo.githubusercontent.com/90c54403fd051879ac9d1a300d8ecde94abba41808d6e6ce30a2c01a87545663/68747470733a2f2f636972636c6563692e636f6d2f67682f536c6963696e67446963652f736c6963696e67646963652d7068702f747265652f6d61737465722e7376673f7374796c653d737667)](https://circleci.com/gh/SlicingDice/slicingdice-php/tree/master)

[](#build-status-)

### Code Quality: [![Codacy Badge](https://camo.githubusercontent.com/73c4b34e116a8a4997668f33ee85373a01894e5d00751b53d4b9cc5b49535104/68747470733a2f2f6170692e636f646163792e636f6d2f70726f6a6563742f62616467652f47726164652f3064353863613932613663353461343161643330653634336262383436343834)](https://www.codacy.com/app/SimbioseVentures/slicingdice-php?utm_source=github.com&utm_medium=referral&utm_content=SlicingDice/slicingdice-php&utm_campaign=Badge_Grade)

[](#code-quality-)

Documentation
-------------

[](#documentation)

If you are new to SlicingDice, check our [quickstart guide](https://docs.slicingdice.com/docs/quickstart-guide) and learn to use it in 15 minutes.

Please refer to the [SlicingDice official documentation](https://docs.slicingdice.com/) for more information on [how to create a database](https://docs.slicingdice.com/docs/how-to-create-a-database), [how to insert data](https://docs.slicingdice.com/docs/how-to-insert-data), [how to make queries](https://docs.slicingdice.com/docs/how-to-make-queries), [how to create columns](https://docs.slicingdice.com/docs/how-to-create-columns), [SlicingDice restrictions](https://docs.slicingdice.com/docs/current-restrictions) and [API details](https://docs.slicingdice.com/docs/api-details).

Tests and Examples
------------------

[](#tests-and-examples)

Whether you want to test the client installation or simply check more examples on how the client works, take a look at [tests and examples directory](tests_and_examples/).

Installing
----------

[](#installing)

In order to install the PHP client, add the following excerpt to your [`composer.json`](https://getcomposer.org/) file.

```
{
  "require": {
    "slicingdice/slicingdice": "*"
  }
}
```

Install the dependencies by executing the command below:

```
composer install
```

### Troubleshooting

[](#troubleshooting)

If you have problem to install on Linux, try to install these system dependencies:

```
# PHP 7
sudo apt-get install php-curl php7.0-dom php7.0-mbstring php7.0-xml
# PHP >= 5.2.8
sudo apt-get install php-curl php5.6-dom php-mbstring php5.6-xml
```

Usage
-----

[](#usage)

The following code snippet is an example of how to add and query data using the SlicingDice PHP client. We entry data informing `user1@slicingdice.com` has age 22 and then query the database for the number of users with age between 20 and 40 years old. If this is the first register ever entered into the system, the answer should be 1.

```

```

Reference
---------

[](#reference)

`SlicingDice` encapsulates logic for sending requests to the API. Its methods are thin layers around the [API endpoints](https://docs.slicingdice.com/docs/api-details), so their parameters and return values are JSON-like `Object` objects with the same syntax as the [API endpoints](https://docs.slicingdice.com/docs/api-details)

### Attributes

[](#attributes)

- `$key (array)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API.
- `$timeout (int)` - Amount of time, in seconds, to wait for results for each request.

### Constructor

[](#constructor)

`_construct($key, $timeout=60)`

- `$key (array)` - [API key](https://docs.slicingdice.com/docs/api-keys) to authenticate requests with the SlicingDice API.
- `$timeout (int)` - Amount of time, in seconds, to wait for results for each request.

### `getDatabase()`

[](#getdatabase)

Get information about current database. This method corresponds to a `GET` request at `/database`.

#### Request example

[](#request-example)

```

```

#### Output example

[](#output-example)

```
{
    "name": "Database 1",
    "description": "My first database",
    "tables": [
    	"default",
        "users"
    ],
    "updated-at": "2017-05-19T14:27:47.417415",
    "created-at": "2017-05-12T02:23:34.231418"
}
```

### `getColumns()`

[](#getcolumns)

Get all created columns, both active and inactive ones. This method corresponds to a [GET request at /column](https://docs.slicingdice.com/docs/how-to-list-edit-or-delete-columns).

#### Request example

[](#request-example-1)

```

```

#### Output example

[](#output-example-1)

```
{
    "active": [
        {
          "name": "Model",
          "api-name": "car-model",
          "description": "Car models from dealerships",
          "type": "string",
          "category": "general",
          "cardinality": "high",
          "storage": "latest-value"
        }
    ],
    "inactive": [
        {
          "name": "Year",
          "api-name": "car-year",
          "description": "Year of manufacture",
          "type": "integer",
          "category": "general",
          "storage": "latest-value"
        }
    ]
}
```

### `createColumn($jsonData)`

[](#createcolumnjsondata)

Create a new column. This method corresponds to a [POST request at /column](https://docs.slicingdice.com/docs/how-to-create-columns#section-creating-columns-using-column-endpoint).

#### Request example

[](#request-example-2)

```

```

#### Output example

[](#output-example-2)

```
{
    "status": "success",
    "api-name": "year"
}
```

### `insert($jsonData)`

[](#insertjsondata)

Insert data to existing entities or create new entities, if necessary. This method corresponds to a [POST request at /insert](https://docs.slicingdice.com/docs/how-to-insert-data).

#### Request example

[](#request-example-3)

```

```

#### Output example

[](#output-example-3)

```
{
    "status": "success",
    "inserted-entities": 4,
    "inserted-columns": 10,
    "took": 0.023
}
```

### `existsEntity($ids, $dimension)`

[](#existsentityids-dimension)

Verify which entities exist in a dimension (uses `default` dimension if not provided) given a list of entity IDs. This method corresponds to a [POST request at /query/exists/entity](https://docs.slicingdice.com/docs/exists).

#### Request example

[](#request-example-4)

```

```

#### Output example

[](#output-example-4)

```
{
    "status": "success",
    "exists": [
        "user1@slicingdice.com",
        "user2@slicingdice.com"
    ],
    "not-exists": [
        "user3@slicingdice.com"
    ],
    "took": 0.103
}
```

### `countEntityTotal()`

[](#countentitytotal)

Count the number of inserted entities in the whole database. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total).

#### Request example

[](#request-example-5)

```

```

#### Output example

[](#output-example-5)

```
{
    "status": "success",
    "result": {
        "total": 42
    },
    "took": 0.103
}
```

### `countEntityTotal($dimensions)`

[](#countentitytotaldimensions)

Count the total number of inserted entities in the given dimensions. This method corresponds to a [POST request at /query/count/entity/total](https://docs.slicingdice.com/docs/total#section-counting-specific-tables).

#### Request example

[](#request-example-6)

```

```

#### Output example

[](#output-example-6)

```
{
    "status": "success",
    "result": {
        "total": 42
    },
    "took": 0.103
}
```

### `countEntity($jsonData)`

[](#countentityjsondata)

Count the number of entities matching the given query. This method corresponds to a [POST request at /query/count/entity](https://docs.slicingdice.com/docs/count-entities).

#### Request example

[](#request-example-7)

```

```

#### Output example

[](#output-example-7)

```
{
   "result":{
      "ford-ka":2,
      "corolla-or-fit":2
   },
   "took":0.083,
   "status":"success"
}
```

### `countEvent($jsonData)`

[](#counteventjsondata)

Count the number of occurrences for time-series events matching the given query. This method corresponds to a [POST request at /query/count/event](https://docs.slicingdice.com/docs/count-events).

#### Request example

[](#request-example-8)

```

```

#### Output example

[](#output-example-8)

```
{
   "result":{
      "test-drives-in-ny":3,
      "test-drives-in-ca":0
   },
   "took":0.063,
   "status":"success"
}
```

### `topValues($jsonData)`

[](#topvaluesjsondata)

Return the top values for entities matching the given query. This method corresponds to a [POST request at /query/top\_values](https://docs.slicingdice.com/docs/top-values).

#### Request example

[](#request-example-9)

```

```

#### Output example

[](#output-example-9)

```
{
   "result":{
      "car models":{
         "car-model":[
            {
               "quantity":2,
               "value":"ford ka"
            },
            {
               "quantity":1,
               "value":"honda fit"
            },
            {
               "quantity":1,
               "value":"toyota corolla"
            }
         ]
      },
      "car-year":{
         "year":[
            {
               "quantity":2,
               "value":"2016"
            },
            {
               "quantity":1,
               "value":"2010"
            }
         ]
      }
   },
   "took":0.034,
   "status":"success"
}
```

### `aggregation($jsonData)`

[](#aggregationjsondata)

Return the aggregation of all columns in the given query. This method corresponds to a [POST request at /query/aggregation](https://docs.slicingdice.com/docs/aggregations).

#### Request example

[](#request-example-10)

```

```

#### Output example

[](#output-example-10)

```
{
   "result":{
      "year":[
         {
            "quantity":2,
            "value":"2016",
            "car-model":[
               {
                  "quantity":1,
                  "value":"honda fit"
               }
            ]
         },
         {
            "quantity":1,
            "value":"2005"
         }
      ]
   },
   "took":0.079,
   "status":"success"
}
```

### `getSavedQueries()`

[](#getsavedqueries)

Get all saved queries. This method corresponds to a [GET request at /query/saved](https://docs.slicingdice.com/docs/saved-queries).

#### Request example

[](#request-example-11)

```

```

#### Output example

[](#output-example-11)

```
{
    "status": "success",
    "saved-queries": [
        {
            "name": "users-in-ny-or-from-ca",
            "type": "count/entity",
            "query": [
                {
                    "state": {
                        "equals": "NY"
                    }
                },
                "or",
                {
                    "state-origin": {
                        "equals": "CA"
                    }
                }
            ],
            "cache-period": 100
        }, {
            "name": "users-from-ca",
            "type": "count/entity",
            "query": [
                {
                    "state": {
                        "equals": "NY"
                    }
                }
            ],
            "cache-period": 60
        }
    ],
    "took": 0.103
}
```

### `createSavedQuery($jsonData)`

[](#createsavedqueryjsondata)

Create a saved query at SlicingDice. This method corresponds to a [POST request at /query/saved](https://docs.slicingdice.com/docs/saved-queries).

#### Request example

[](#request-example-12)

```

```

#### Output example

[](#output-example-12)

```
{
   "took":0.053,
   "query":[
      {
         "car-model":{
            "equals":"honda fit"
         }
      },
      "or",
      {
         "car-model":{
            "equals":"toyota corolla"
         }
      }
   ],
   "name":"my-saved-query",
   "type":"count/entity",
   "cache-period":100,
   "status":"success"
}
```

### `updateSavedQuery($queryName, $jsonData)`

[](#updatesavedqueryqueryname-jsondata)

Update an existing saved query at SlicingDice. This method corresponds to a [PUT request at /query/saved/QUERY\_NAME](https://docs.slicingdice.com/docs/saved-queries).

#### Request example

[](#request-example-13)

```

```

#### Output example

[](#output-example-13)

```
{
   "took":0.037,
   "query":[
      {
         "car-model":{
            "equals":"ford ka"
         }
      },
      "or",
      {
         "car-model":{
            "equals":"toyota corolla"
         }
      }
   ],
   "type":"count/entity",
   "cache-period":100,
   "status":"success"
}
```

### `getSavedQuery($queryName)`

[](#getsavedqueryqueryname)

Executed a saved query at SlicingDice. This method corresponds to a [GET request at /query/saved/QUERY\_NAME](https://docs.slicingdice.com/docs/saved-queries).

#### Request example

[](#request-example-14)

```

```

#### Output example

[](#output-example-14)

```
{
   "result":{
      "query":2
   },
   "took":0.035,
   "query":[
      {
         "car-model":{
            "equals":"honda fit"
         }
      },
      "or",
      {
         "car-model":{
            "equals":"toyota corolla"
         }
      }
   ],
   "type":"count/entity",
   "status":"success"
}
```

### `deleteSavedQuery($queryName)`

[](#deletesavedqueryqueryname)

Delete a saved query at SlicingDice. This method corresponds to a [DELETE request at /query/saved/QUERY\_NAME](https://docs.slicingdice.com/docs/saved-queries).

#### Request example

[](#request-example-15)

```

```

#### Output example

[](#output-example-15)

```
{
   "took":0.029,
   "query":[
      {
         "car-model":{
            "equals":"honda fit"
         }
      },
      "or",
      {
         "car-model":{
            "equals":"toyota corolla"
         }
      }
   ],
   "type":"count/entity",
   "cache-period":100,
   "status":"success",
   "deleted-query":"my-saved-query"
}
```

### `result($jsonData)`

[](#resultjsondata)

Retrieve inserted values for entities matching the given query. This method corresponds to a [POST request at /data\_extraction/result](https://docs.slicingdice.com/docs/result-extraction).

#### Request example

[](#request-example-16)

```

```

#### Output example

[](#output-example-16)

```
{
   "took":0.113,
   "next-page":null,
   "data":{
      "customer5@mycustomer.com":{
         "year":"2005",
         "car-model":"ford ka"
      },
      "user1@slicingdice.com":{
         "year":"2016",
         "car-model":"ford ka"
      }
   },
   "page":1,
   "status":"success"
}
```

### `score($jsonData)`

[](#scorejsondata)

Retrieve inserted values as well as their relevance for entities matching the given query. This method corresponds to a [POST request at /data\_extraction/score](https://docs.slicingdice.com/docs/score-extraction).

#### Request example

[](#request-example-17)

```

```

#### Output example

[](#output-example-17)

```
{
   "took":0.063,
   "next-page":null,
   "data":{
      "user3@slicingdice.com":{
         "score":1,
         "year":"2010",
         "car-model":"toyota corolla"
      },
      "user2@slicingdice.com":{
         "score":1,
         "year":"2016",
         "car-model":"honda fit"
      }
   },
   "page":1,
   "status":"success"
}
```

### `sql($query)`

[](#sqlquery)

Retrieve inserted values using a SQL syntax. This method corresponds to a POST request at /query/sql.

#### Query statement

[](#query-statement)

```

```

#### Insert statement

[](#insert-statement)

```
