Skip to content

Repository files navigation

README

phpOlap is a php API for OLAP (XMLA)

phpOlap can be used to explore schema (cubes, dimensions, hierarchies, levels, ...) and execute MDX Query, generate layout, ...

phpOlap is only supported on PHP 5.3.2 and up.

API : http://phpolap.org/

Database exploration

<?phprequire_once'../autoload.php';
usephpOlap\Xmla\Connection\Connection;
usephpOlap\Xmla\Connection\Adaptator\SoapAdaptator;
// for Mondrian$connection = newConnection(
newSoapAdaptator('http://localhost:8080/mondrian/xmla'),
array(
'DataSourceInfo' => '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'));
?>
<p><label>Cube :</label> <?phpecho$cube->getName() ?></p>
<ul id="cubeExploration">
<li class="measure">
Measures
<ul>
<?phpforeach ($cube->getMeasures() as$measure): ?>
<li><?phpecho$measure->getCaption() ?></li>
<?phpendforeach?>
</ul>
</li> <?phpforeach ($cube->getDimensionsAndHierarchiesAndLevels() as$dimention): ?><?phpif($dimention->getType() != 'MEASURE') : ?>
<li>
<?phpecho$dimention->getCaption() ?>
<ul>
<?phpforeach ($dimention->getHierarchies() as$hierarchy): ?>
<li>
<?phpecho$hierarchy->getCaption() ?>
<ul>
<?phpforeach ($hierarchy->getLevels() as$level): ?>
<li>
<?phpecho$level->getCaption() ?>
</li>
<?phpendforeach?>
</ul>
</li>
<?phpendforeach?>
</ul>
</li>
<?phpendif; ?><?phpendforeach?>
</ul>

Query

<?phprequire_once'../autoload.php';
usephpOlap\Mdx\Query;
$query = newQuery("[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

<?phprequire_once'../autoload.php';
usephpOlap\Xmla\Connection\Connection;
usephpOlap\Xmla\Connection\Adaptator\SoapAdaptator;
usephpOlap\Layout\Table\HtmlTableLayout;
usephpOlap\Layout\Table\CsvTableLayout;
$connection = ...$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]}");
// html table$table = newHtmlTableLayout($resultSet);
echo$table->generate();
// csvheader("Content-type: application/vnd.ms-excel"); header("Content-disposition: attachment; filename=\"export.csv\"");
$csv = newCsvTableLayout($resultSet);
print($csv->generate()); exit;

About

PHP API for OLAP (BETA)

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages