1. Go to this page and download the library: Download th3mouk/materialized-view library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
th3mouk / materialized-view example snippets
use Th3Mouk\MaterializedView\Core\Definition\MaterializedViewDefinition;
use Th3Mouk\MaterializedView\Core\Definition\MaterializedViewIndex;
use Th3Mouk\MaterializedView\Core\Definition\SqlFileSource;
use Th3Mouk\MaterializedView\Core\Registry\MaterializedViewRegistry;
$definition = MaterializedViewDefinition::create('public.sales_by_category')
->fromSql(SqlFileSource::fromProjectPath('db/matviews/sales_by_category.sql'))
->withIndex(MaterializedViewIndex::unique(
name: 'ux_sales_by_category_category',
columns: ['category'],
));
$registry = MaterializedViewRegistry::fromDefinitions([$definition]);
use Th3Mouk\MaterializedView\Core\MaterializedViewManager;
// With Doctrine DBAL (recommended — primary/replica routing, middlewares, profiling):
$manager = MaterializedViewManager::forConnection($dbalConnection);
// …or without Doctrine, on a bare PDO connection:
$manager = MaterializedViewManager::forPdo(new PDO($dsn, $user, $password));
$manager->syncAll($registry); // create / rebuild on drift
$manager->refresh($definition); // REFRESH MATERIALIZED VIEW (CONCURRENTLY when possible)
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.