README
phpOlap is a php API for OLAP (XMLA), (*1)
phpOlap can be used to explore schema (cubes, dimensions, hierarchies, levels, ...) and execute MDX Query, generate layout, ..., (*2)
phpOlap is only supported on PHP 5.3.2 and up., (*3)
API : http://phpolap.org/, (*4)
Database exploration
``` php
'Provider=Mondrian;DataSource=MondrianFoodMart;'
'CatalogName' => 'FoodMart',
'schemaName' => 'FoodMart'
)
);
// for Microsoft SQL Server Analysis Services
/*
$connection = new Connection(
new SoapAdaptator('http://192.168.1.12/olap/msmdpump.dll', 'julien', 'juju'),
array(
'DataSourceInfo' => null,
'CatalogName' => 'Adventure Works DW 2008R2 SE'
)
);
*/
$cube = $connection->findOneCube(null, array('CUBE_NAME' => 'Sales'));
?>, (*5)
Cube : getName() ?>, (*6)
Measures
getMeasures() as $measure): ?>
getCaption() ?>
getDimensionsAndHierarchiesAndLevels() as $dimention): ?>
getType() != 'MEASURE') : ?>
getCaption() ?>
getHierarchies() as $hierarchy): ?>
getCaption() ?>
getLevels() as $level): ?>
getCaption() ?>
Query
-----
``` php
<?php
require_once '../autoload.php';
use phpOlap\Mdx\Query;
$query = new Query("[Sales]");
$query->addElement("[Measures].[Unit Sales]", "COL");
$query->addElement("[Measures].[Store Cost]", "COL");
$query->addElement("[Measures].[Store Sales]", "COL");
$query->addElement("[Gender].[All Gender].Children", "COL");
$query->addElement("[Promotion Media].[All Media]", "ROW");
$query->addElement("[Product].[All Products].[Drink].[Alcoholic Beverages]", "ROW");
$query->addElement("[Promotion Media].[All Media].Children", "ROW");
$query->addElement("[Product].[All Products]", "ROW");
$query->addElement("[Time].[1997]", "FILTER");
echo $query->toMdx();
Layout
``` php
<?php
require_once '../autoload.php';, (*7)
use phpOlap\Xmla\Connection\Connection;
use phpOlap\Xmla\Connection\Adaptator\SoapAdaptator;
use phpOlap\Layout\Table\HtmlTableLayout;
use phpOlap\Layout\Table\CsvTableLayout;, (*8)
$connection = ..., (*9)
$resultSet = $connection->statement("
select Hierarchize(Union(Union({([Measures].[Unit Sales], [Gender].[All Gender], [Marital Status].[All Marital Status])}, Union(Union(Crossjoin({[Measures].[Store Cost]}, {([Gender].[All Gender], [Marital Status].[All Marital Status])}), Crossjoin({[Measures].[Store Cost]}, Crossjoin([Gender].[All Gender].Children, {[Marital Status].[All Marital Status]}))), Crossjoin({[Measures].[Store Cost]}, Crossjoin({[Gender].[F]}, [Marital Status].[All Marital Status].Children)))), Crossjoin({[Measures].[Store Sales]}, Union(Crossjoin({[Gender].[All Gender]}, {[Marital Status].[All Marital Status]}), Crossjoin({[Gender].[All Gender]}, [Marital Status].[All Marital Status].Children))))) ON COLUMNS,
Crossjoin(Hierarchize(Crossjoin(Union({[Promotion Media].[All Media]}, [Promotion Media].[All Media].Children), Union(Union({[Product].[All Products]}, [Product].[All Products].Children), [Product].[Food].Children))), {[Store].[All Stores]}) ON ROWS
from [Sales]
where {[Time].[1997]}, (*10)
");, (*11)
// html table
$table = new HtmlTableLayout($resultSet);
echo $table->generate();, (*12)
// csv
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=\"export.csv\"");
$csv = new CsvTableLayout($resultSet);
print($csv->generate());
exit;, (*13)