PHPackages                             sorexalpinus/cubify - 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. sorexalpinus/cubify

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

sorexalpinus/cubify
===================

Cubify your SQL query

0.1.3(3y ago)1252MITPHPPHP &gt;=7.1.0CI failing

Since Jan 5Pushed 3y ago1 watchersCompare

[ Source](https://github.com/sorexalpinus/cubify)[ Packagist](https://packagist.org/packages/sorexalpinus/cubify)[ RSS](/packages/sorexalpinus-cubify/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (5)Used By (0)

Cubify
======

[](#cubify)

Cubify your SQL query

Cubify package creates a patch over standard MySQL/MariaDB behaviour where CUBE function is not available. All you need to do is choose your DBMS and provide your query, along with dimensions, measures and masks.

Example
-------

[](#example)

The table "spotted\_animals" tracks animals spotted in different areas in Banff NP Canada in winter:

YearTransectSpeciesSnow depthNum animals2015Dog LoopNULL3002014Cascadefox212016Hoodooselk2622015Airfieldelk1172015Dog Loopdeer1112016Airfieldcoyote1432015Airfielddeer1622016Healy Northdeer241201640 Milecoyote121*more rows...*##### To find:

[](#to-find)

average snow depth and total number of animals spotted:

- per year,transect and species
- per year and transect, regardless of species
- per year and species, regardless of transect

##### use MysqlCube:

[](#use-mysqlcube)

```
$cube = new MysqlCube(
    //sql connection
    new mysqli('localhost','root','','wildlife_test',3308),
    //base query
    'SELECT * FROM spotted_animals',
    //masks
    ['111', '110', '101'],
    //dimensions
    ['Transect', 'Year', 'Species'],
    //measures & aggregate functions
     ['Snow depth' => 'AVG', 'Num animals' => 'SUM']
);
$data = $cube->getResultDataset();
print_r($data);
```

5 arguments were passed:

1. MySQL database connection
2. Base query - this is a statement you want to cubify (use CUBE)
3. Masks represent grouping sets with regard to dimensions` order (see table below)
4. Dimensions are "GROUP BY" columns
5. Measures are numbers to be aggregated by per each combination

MaskTransectYearSpeciesSnow depthNum animals111valuevaluevalueAVG(Snow depth)SUM(Num animals)110valuevalue(total)AVG(Snow depth)SUM(Num animals)101value(total)valueAVG(Snow depth)SUM(Num animals)##### Use output:

[](#use-output)

Method getResultDataset() returns array which can be translated to a following table:

MaskTransectYearSpeciesSnow depthNum animals101Cascade(total)fox18.000010101Dog Loop(total)elk25.789544101Dog Loop(total)fox21.50002110Cascade2014(total)15.5444122110Cascade2015(total)18.4649114110Cascade2016(total)19.3472116110Dog Loop2014(total)10.1221127110Dog Loop2015(total)25.7264102110Dog Loop2016(total)21.3565172111Cascade2014elk21.411890111Cascade2014fox2.00002111Cascade2015elk19.750057111Cascade2015fox22.57148111Cascade2016elk21.687546111Dog Loop2014elk6.50006111Dog Loop2015elk31.000019111Dog Loop2016fox21.50002*more rows...*Output methods
--------------

[](#output-methods)

**`getCubeQuery()`** returns final query that can be used for further SQL operations

**`getResult()`** returns SQL result object

**`getResultDataset()`** returns the complete dataset as an array

Known limitations
-----------------

[](#known-limitations)

- Cubify does not provide Cartesian cube (all combinations for all dimensions values), the final dataset only contains only combinations that exist in the base query dataset
- At the moment, it can be only used with MySQL (though other "cubes" can be added easily implementing the SqlCube interface)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~402 days

Total

4

Last Release

1109d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/dd26d9c08fdc087610871e227c487c490a17021feeb78d2060380ff9e45722b9?d=identicon)[sorexalpinus](/maintainers/sorexalpinus)

---

Top Contributors

[![sorexalpinus](https://avatars.githubusercontent.com/u/57848381?v=4)](https://github.com/sorexalpinus "sorexalpinus (29 commits)")

---

Tags

cubemysqlolapphp7pivotmysqlPHP7cubepivotolap

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/sorexalpinus-cubify/health.svg)

```
[![Health](https://phpackages.com/badges/sorexalpinus-cubify/health.svg)](https://phpackages.com/packages/sorexalpinus-cubify)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k578.4M5.6k](/packages/doctrine-dbal)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k5.5M69](/packages/ifsnop-mysqldump-php)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k25.2M34](/packages/kirschbaum-development-eloquent-power-joins)[scienta/doctrine-json-functions

A set of extensions to Doctrine that add support for json query functions.

58523.9M35](/packages/scienta-doctrine-json-functions)[clouddueling/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k22.9k](/packages/clouddueling-mysqldump-php)[mattbit/mysql-compat

Backward compatibility for old mysql\_\* functions with PDO

2653.7k](/packages/mattbit-mysql-compat)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
